Struct artichoke::prelude::Guard[][src]

pub struct Guard<'a>(_);

Interpreter guard that prepares an Artichoke to re-enter an FFI boundary.

Artichoke integrates with the mruby VM via many extern "C" fn trampolines that are invoked by mruby to run some portion of the VM in Rust.

These trampolines typically require an Artichoke interpreter to do useful work, so they move the State out of the mrb userdata pointer into an Artichoke struct.

To ensure safety, the State must be moved back into the mrb userdata pointer before re-entering the FFI boundary. This guard implements Drop to reserialize the State into the mrb once it goes out of scope.

Guard is passed directly to error::raise.

Implementations

impl<'a> Guard<'a>[src]

pub fn new(interp: &'a mut Artichoke) -> Guard<'a>[src]

Create a new guard that wraps an interpreter.

This function is most effective when the interpreter is temporarily reified and stored on the stack.

pub fn interp(&mut self) -> &mut Artichoke[src]

Access the inner guarded interpreter.

The interpreter is also accessible via Deref, DerefMut, AsRef, and AsMut.

Methods from Deref<Target = Artichoke>

pub fn protect(&mut self, value: Value) -> Value[src]

Prevent the given value from being garbage collected.

Calls sys::mrb_gc_protect on this value which adds it to the GC arena. This object will remain in the arena until ArenaIndex::restore restores the arena to an index before this call to protect.

pub unsafe fn with_ffi_boundary<F, T>(
    &mut self,
    func: F
) -> Result<T, InterpreterExtractError> where
    F: FnOnce(*mut mrb_state) -> T, 
[src]

Execute a a closure by moving the State into the mrb instance.

This method prepares this interpreter to cross an FFI boundary. When the Artichoke implementation calls mruby FFI functions, the State must be moved into the sys::mrb_state userdata pointer.

Safety

This method moves the State out of this instance into the mrb instance. During this function’s execution, this instance may be partially initialized.

This function is only safe to call if the closure only calls FFI functions that use a raw *mut sys::mrb_state.

pub fn lookup_symbol_with_trailing_nul(
    &self,
    symbol: u32
) -> Result<Option<&[u8]>, Error>
[src]

pub fn intern_bytes_with_trailing_nul<T>(
    &mut self,
    bytes: T
) -> Result<u32, Error> where
    T: Into<Cow<'static, [u8]>>, 
[src]

pub fn check_interned_bytes_with_trailing_nul(
    &self,
    bytes: &[u8]
) -> Result<Option<u32>, Error>
[src]

Trait Implementations

impl<'a> AsMut<Artichoke> for Guard<'a>[src]

pub fn as_mut(&mut self) -> &mut Artichoke[src]

Performs the conversion.

impl<'a> AsRef<Artichoke> for Guard<'a>[src]

pub fn as_ref(&self) -> &Artichoke[src]

Performs the conversion.

impl<'a> Debug for Guard<'a>[src]

pub fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>[src]

Formats the value using the given formatter. Read more

impl<'a> Deref for Guard<'a>[src]

type Target = Artichoke

The resulting type after dereferencing.

pub fn deref(&self) -> &<Guard<'a> as Deref>::Target[src]

Dereferences the value.

impl<'a> DerefMut for Guard<'a>[src]

pub fn deref_mut(&mut self) -> &mut <Guard<'a> as Deref>::Target[src]

Mutably dereferences the value.

impl<'a> Drop for Guard<'a>[src]

pub fn drop(&mut self)[src]

Executes the destructor for this type. Read more

Auto Trait Implementations

impl<'a> RefUnwindSafe for Guard<'a>

impl<'a> !Send for Guard<'a>

impl<'a> !Sync for Guard<'a>

impl<'a> Unpin for Guard<'a>

impl<'a> !UnwindSafe for Guard<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 
[src]

pub fn vzip(self) -> V[src]