Struct artichoke_backend::prelude::Guard[][src]

pub struct Guard<'a>(_);
Expand description

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

Create a new guard that wraps an interpreter.

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

Access the inner guarded interpreter.

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

Methods from Deref<Target = Artichoke>

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.

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.

Trait Implementations

Performs the conversion.

Performs the conversion.

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.