pub struct ArenaIndex<'a> { /* private fields */ }
Expand description

Interpreter guard that acts as a GC arena savepoint.

Arena savepoints ensure mruby objects are reaped even when allocated with the C API.

mruby manages objects created via the C API in a memory construct called the arena. The arena is a stack and objects stored there are permanently alive to avoid having to track lifetimes externally to the interpreter.

An ArenaIndex is an index to some position of the stack. When restoring an ArenaIndex, the stack pointer is moved. All objects beyond the pointer are no longer live and are eligible to be collected at the next GC.

ArenaIndex implements Drop, so letting it go out of scope is sufficient to ensure objects get collected eventually.


Create a new arena savepoint.

Restore the arena stack pointer to its prior index.

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.


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

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.