pub struct Artichoke {
pub mrb: NonNull<mrb_state>,
pub state: Option<Box<State>>,
}
Expand description
Interpreter instance.
Functionality is added to the interpreter via traits, for example, garbage collection or eval.
Fields§
§mrb: NonNull<mrb_state>
Underlying mruby interpreter.
This is an owned reference to the interpreter via a mutable pointer.
state: Option<Box<State>>
Interpreter state.
This field is an Option
because the State
is moved in and out of the
Artichoke
struct as the call graph crosses between Rust and C and C to
Rust.
Implementations§
Source§impl Artichoke
impl Artichoke
Sourcepub const fn new(mrb: NonNull<mrb_state>, state: Box<State>) -> Self
pub const fn new(mrb: NonNull<mrb_state>, state: Box<State>) -> Self
Create a new interpreter from an underlying mrb
and a State
.
Sourcepub fn protect(&mut self, value: Value) -> Value
pub fn protect(&mut self, value: Value) -> Value
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.
Sourcepub unsafe fn with_ffi_boundary<F, T>(
&mut self,
func: F,
) -> Result<T, InterpreterExtractError>
pub unsafe fn with_ffi_boundary<F, T>( &mut self, func: F, ) -> Result<T, InterpreterExtractError>
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
.
Sourcepub unsafe fn into_raw(interp: Self) -> *mut mrb_state
pub unsafe fn into_raw(interp: Self) -> *mut mrb_state
Consume an interpreter and return the pointer to the underlying
sys::mrb_state
.
This function does not free any interpreter resources. Its intended use is to prepare the interpreter to cross over an FFI boundary.
This is an associated function and must be called as
Artichoke::into_raw(interp)
.
§Safety
After calling this function, the caller is responsible for properly
freeing the memory occupied by the interpreter heap. The easiest way to
do this is to call ffi::from_user_data
with the returned pointer and
then call Artichoke::close
.
Source§impl Artichoke
impl Artichoke
Trait Implementations§
Source§impl ClassRegistry for Artichoke
impl ClassRegistry for Artichoke
Source§type Error = Error
type Error = Error
Source§fn def_class<T>(&mut self, spec: Self::Spec) -> Result<(), Self::Error>where
T: Any,
fn def_class<T>(&mut self, spec: Self::Spec) -> Result<(), Self::Error>where
T: Any,
T
. Read moreSource§fn class_spec<T>(&self) -> Result<Option<&Self::Spec>, Self::Error>where
T: Any,
fn class_spec<T>(&self) -> Result<Option<&Self::Spec>, Self::Error>where
T: Any,
T
. Read moreSource§impl CoerceToNumeric for Artichoke
impl CoerceToNumeric for Artichoke
Source§impl ConvertMut<Rand, Value> for Artichoke
impl ConvertMut<Rand, Value> for Artichoke
Source§fn convert_mut(&mut self, from: Rand) -> Value
fn convert_mut(&mut self, from: Rand) -> Value
Source§impl ConvertMut<Rand, Value> for Artichoke
impl ConvertMut<Rand, Value> for Artichoke
Source§fn convert_mut(&mut self, from: Rand) -> Value
fn convert_mut(&mut self, from: Rand) -> Value
Source§impl ConvertMut<Value, Options> for Artichoke
impl ConvertMut<Value, Options> for Artichoke
Source§fn convert_mut(&mut self, value: Value) -> Options
fn convert_mut(&mut self, value: Value) -> Options
Source§impl ConvertMut<Value, Value> for Artichoke
impl ConvertMut<Value, Value> for Artichoke
Source§fn convert_mut(&mut self, value: Value) -> Value
fn convert_mut(&mut self, value: Value) -> Value
Source§impl ConvertMut<f64, Value> for Artichoke
impl ConvertMut<f64, Value> for Artichoke
Source§fn convert_mut(&mut self, value: f64) -> Value
fn convert_mut(&mut self, value: f64) -> Value
Source§impl Debug for Artichoke
impl Debug for Artichoke
Source§impl DefineConstant for Artichoke
impl DefineConstant for Artichoke
Source§fn define_global_constant(
&mut self,
constant: &str,
value: Self::Value,
) -> Result<(), Self::Error>
fn define_global_constant( &mut self, constant: &str, value: Self::Value, ) -> Result<(), Self::Error>
Source§impl Eval for Artichoke
impl Eval for Artichoke
Source§impl Globals for Artichoke
impl Globals for Artichoke
Source§fn unset_global_variable<T>(&mut self, name: T) -> Result<(), Self::Error>
fn unset_global_variable<T>(&mut self, name: T) -> Result<(), Self::Error>
Unset global variable pointed to by name
.
Unsetting a global variable removes the name from the global storage
table. Unset globals resolve to nil
in the Ruby VM.
Unsetting a global that is currently unset is a no-op.
§Errors
If the name is not a valid global name, an error is returned.
Source§impl Hash for Artichoke
impl Hash for Artichoke
Source§type Error = Error
type Error = Error
BuildHasher
.Source§type GlobalBuildHasher = RandomState
type GlobalBuildHasher = RandomState
BuildHasher
type which is global to the interpreter.Source§fn global_build_hasher(
&mut self,
) -> Result<&Self::GlobalBuildHasher, Self::Error>
fn global_build_hasher( &mut self, ) -> Result<&Self::GlobalBuildHasher, Self::Error>
BuildHasher
. Read moreSource§impl Intern for Artichoke
impl Intern for Artichoke
Source§const SYMBOL_RANGE_START: Self::Symbol = {transmute(0x00000001): <artichoke::Artichoke as artichoke_core::intern::Intern>::Symbol}
const SYMBOL_RANGE_START: Self::Symbol = {transmute(0x00000001): <artichoke::Artichoke as artichoke_core::intern::Intern>::Symbol}
Symbol
index returned by the interner. Read moreSource§fn intern_bytes<T>(&mut self, bytes: T) -> Result<Self::Symbol, Self::Error>
fn intern_bytes<T>(&mut self, bytes: T) -> Result<Self::Symbol, Self::Error>
Source§fn check_interned_bytes(
&self,
bytes: &[u8],
) -> Result<Option<Self::Symbol>, Self::Error>
fn check_interned_bytes( &self, bytes: &[u8], ) -> Result<Option<Self::Symbol>, Self::Error>
None
if the string has not been interned before. Read moreSource§fn lookup_symbol(
&self,
symbol: Self::Symbol,
) -> Result<Option<&[u8]>, Self::Error>
fn lookup_symbol( &self, symbol: Self::Symbol, ) -> Result<Option<&[u8]>, Self::Error>
Source§fn symbol_count(&self) -> usize
fn symbol_count(&self) -> usize
Source§impl Io for Artichoke
impl Io for Artichoke
Source§fn print(&mut self, message: &[u8]) -> Result<(), Self::Error>
fn print(&mut self, message: &[u8]) -> Result<(), Self::Error>
Writes the given bytes to the interpreter stdout stream.
This implementation delegates to the underlying output strategy.
§Errors
If the output stream encounters an error, an error is returned.
Source§impl LoadSources for Artichoke
impl LoadSources for Artichoke
Source§fn def_file_for_type<P, T>(&mut self, path: P) -> Result<(), Self::Error>
fn def_file_for_type<P, T>(&mut self, path: P) -> Result<(), Self::Error>
File::require
will dynamically define
Ruby items when invoked via Kernel#require
. Read moreSource§fn def_rb_source_file<P, T>(
&mut self,
path: P,
contents: T,
) -> Result<(), Self::Error>
fn def_rb_source_file<P, T>( &mut self, path: P, contents: T, ) -> Result<(), Self::Error>
Source§fn resolve_source_path<P>(
&self,
path: P,
) -> Result<Option<Vec<u8>>, Self::Error>
fn resolve_source_path<P>( &self, path: P, ) -> Result<Option<Vec<u8>>, Self::Error>
Source§fn source_is_file<P>(&self, path: P) -> Result<bool, Self::Error>
fn source_is_file<P>(&self, path: P) -> Result<bool, Self::Error>
Source§fn load_source<P>(&mut self, path: P) -> Result<Loaded, Self::Error>
fn load_source<P>(&mut self, path: P) -> Result<Loaded, Self::Error>
Source§impl ModuleRegistry for Artichoke
impl ModuleRegistry for Artichoke
Source§type Error = Error
type Error = Error
Source§fn def_module<T>(&mut self, spec: Self::Spec) -> Result<(), Self::Error>where
T: Any,
fn def_module<T>(&mut self, spec: Self::Spec) -> Result<(), Self::Error>where
T: Any,
T
. Read moreSource§fn module_spec<T>(&self) -> Result<Option<&Self::Spec>, Self::Error>where
T: Any,
fn module_spec<T>(&self) -> Result<Option<&Self::Spec>, Self::Error>where
T: Any,
T
. Read moreSource§impl MrbGarbageCollection for Artichoke
impl MrbGarbageCollection for Artichoke
Source§fn create_arena_savepoint(
&mut self,
) -> Result<ArenaIndex<'_>, ArenaSavepointError>
fn create_arena_savepoint( &mut self, ) -> Result<ArenaIndex<'_>, ArenaSavepointError>
Source§fn live_object_count(&mut self) -> usize
fn live_object_count(&mut self) -> usize
Source§fn mark_value(&mut self, value: &Value) -> Result<(), Error>
fn mark_value(&mut self, value: &Value) -> Result<(), Error>
Value
as reachable in the mruby garbage collector.Source§impl Parser for Artichoke
impl Parser for Artichoke
Source§fn reset_parser(&mut self) -> Result<(), Self::Error>
fn reset_parser(&mut self) -> Result<(), Self::Error>
Source§fn fetch_lineno(&self) -> Result<usize, Self::Error>
fn fetch_lineno(&self) -> Result<usize, Self::Error>
Source§fn add_fetch_lineno(&mut self, val: usize) -> Result<usize, Self::Error>
fn add_fetch_lineno(&mut self, val: usize) -> Result<usize, Self::Error>
Source§fn push_context(&mut self, context: Self::Context) -> Result<(), Self::Error>
fn push_context(&mut self, context: Self::Context) -> Result<(), Self::Error>
Source§impl Prng for Artichoke
Available on crate feature core-random
only.
impl Prng for Artichoke
core-random
only.Source§impl Regexp for Artichoke
Available on crate feature core-regexp
only.
impl Regexp for Artichoke
core-regexp
only.Source§type Error = InterpreterExtractError
type Error = InterpreterExtractError
Regexp
state.Source§fn capture_group_globals(&self) -> Result<usize, Self::Error>
fn capture_group_globals(&self) -> Result<usize, Self::Error>
Regexp
capture group global
variables. Read moreSource§impl<T, U> TryConvert<T, U> for Artichoke
Provide a fallible converter for types that implement an infallible
conversion.
impl<T, U> TryConvert<T, U> for Artichoke
Provide a fallible converter for types that implement an infallible conversion.
Source§fn try_convert(&self, value: T) -> Result<U, Self::Error>
fn try_convert(&self, value: T) -> Result<U, Self::Error>
Blanket implementation that always succeeds by delegating to
Convert::convert
.
Source§impl TryConvertMut<(Option<Value>, Option<Value>), (Option<Options>, Option<Encoding>)> for Artichoke
impl TryConvertMut<(Option<Value>, Option<Value>), (Option<Options>, Option<Encoding>)> for Artichoke
Source§impl<T, U> TryConvertMut<T, U> for Artichokewhere
Artichoke: ConvertMut<T, U>,
Provide a mutable fallible converter for types that implement an infallible
conversion.
impl<T, U> TryConvertMut<T, U> for Artichokewhere
Artichoke: ConvertMut<T, U>,
Provide a mutable fallible converter for types that implement an infallible conversion.
Source§fn try_convert_mut(&mut self, value: T) -> Result<U, Self::Error>
fn try_convert_mut(&mut self, value: T) -> Result<U, Self::Error>
Blanket implementation that always succeeds by delegating to
Convert::convert
.