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>) -> Artichoke
pub const fn new(mrb: NonNull<mrb_state>, state: Box<State>) -> Artichoke
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: Artichoke) -> *mut mrb_state
pub unsafe fn into_raw(interp: Artichoke) -> *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: <Artichoke as ClassRegistry>::Spec,
) -> Result<(), <Artichoke as ClassRegistry>::Error>where
T: Any,
fn def_class<T>(
&mut self,
spec: <Artichoke as ClassRegistry>::Spec,
) -> Result<(), <Artichoke as ClassRegistry>::Error>where
T: Any,
T
. Read moreSource§fn class_spec<T>(
&self,
) -> Result<Option<&<Artichoke as ClassRegistry>::Spec>, <Artichoke as ClassRegistry>::Error>where
T: Any,
fn class_spec<T>(
&self,
) -> Result<Option<&<Artichoke as ClassRegistry>::Spec>, <Artichoke as ClassRegistry>::Error>where
T: Any,
T
. Read moreSource§fn class_of<T>(
&mut self,
) -> Result<Option<<Artichoke as ClassRegistry>::Value>, <Artichoke as ClassRegistry>::Error>where
T: Any,
fn class_of<T>(
&mut self,
) -> Result<Option<<Artichoke as ClassRegistry>::Value>, <Artichoke as ClassRegistry>::Error>where
T: Any,
Source§fn new_instance<T>(
&mut self,
args: &[<Artichoke as ClassRegistry>::Value],
) -> Result<Option<<Artichoke as ClassRegistry>::Value>, <Artichoke as ClassRegistry>::Error>where
T: Any,
fn new_instance<T>(
&mut self,
args: &[<Artichoke as ClassRegistry>::Value],
) -> Result<Option<<Artichoke as ClassRegistry>::Value>, <Artichoke as ClassRegistry>::Error>where
T: Any,
T
. Read moreSource§impl CoerceToNumeric for Artichoke
impl CoerceToNumeric for Artichoke
Source§fn coerce_to_float(
&mut self,
value: <Artichoke as CoerceToNumeric>::Value,
) -> Result<<Artichoke as CoerceToNumeric>::Float, <Artichoke as CoerceToNumeric>::Error>
fn coerce_to_float( &mut self, value: <Artichoke as CoerceToNumeric>::Value, ) -> Result<<Artichoke as CoerceToNumeric>::Float, <Artichoke as CoerceToNumeric>::Error>
Float
. Read moreSource§impl ConvertMut<Float, Value> for Artichoke
impl ConvertMut<Float, Value> for Artichoke
Source§fn convert_mut(&mut self, from: Float) -> Value
fn convert_mut(&mut self, from: Float) -> Value
Source§impl ConvertMut<Outcome, Value> for Artichoke
impl ConvertMut<Outcome, Value> for Artichoke
Source§fn convert_mut(&mut self, from: Outcome) -> Value
fn convert_mut(&mut self, from: Outcome) -> 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<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: <Artichoke as DefineConstant>::Value,
) -> Result<(), <Artichoke as DefineConstant>::Error>
fn define_global_constant( &mut self, constant: &str, value: <Artichoke as DefineConstant>::Value, ) -> Result<(), <Artichoke as DefineConstant>::Error>
Source§fn define_class_constant<T>(
&mut self,
constant: &str,
value: <Artichoke as DefineConstant>::Value,
) -> Result<(), <Artichoke as DefineConstant>::Error>where
T: 'static,
fn define_class_constant<T>(
&mut self,
constant: &str,
value: <Artichoke as DefineConstant>::Value,
) -> Result<(), <Artichoke as DefineConstant>::Error>where
T: 'static,
Source§fn define_module_constant<T>(
&mut self,
constant: &str,
value: <Artichoke as DefineConstant>::Value,
) -> Result<(), <Artichoke as DefineConstant>::Error>where
T: 'static,
fn define_module_constant<T>(
&mut self,
constant: &str,
value: <Artichoke as DefineConstant>::Value,
) -> Result<(), <Artichoke as DefineConstant>::Error>where
T: 'static,
Source§impl Eval for Artichoke
impl Eval for Artichoke
Source§fn eval(
&mut self,
code: &[u8],
) -> Result<<Artichoke as Eval>::Value, <Artichoke as Eval>::Error>
fn eval( &mut self, code: &[u8], ) -> Result<<Artichoke as Eval>::Value, <Artichoke as Eval>::Error>
Source§impl Globals for Artichoke
impl Globals for Artichoke
Source§fn unset_global_variable<T>(
&mut self,
name: T,
) -> Result<(), <Artichoke as Globals>::Error>
fn unset_global_variable<T>( &mut self, name: T, ) -> Result<(), <Artichoke as Globals>::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<&<Artichoke as Hash>::GlobalBuildHasher, <Artichoke as Hash>::Error>
fn global_build_hasher( &mut self, ) -> Result<&<Artichoke as Hash>::GlobalBuildHasher, <Artichoke as Hash>::Error>
BuildHasher
. Read moreSource§impl Intern for Artichoke
impl Intern for Artichoke
Source§const SYMBOL_RANGE_START: <Artichoke as Intern>::Symbol = {transmute(0x00000001): <artichoke_backend::Artichoke as artichoke_backend::prelude::Intern>::Symbol}
const SYMBOL_RANGE_START: <Artichoke as Intern>::Symbol = {transmute(0x00000001): <artichoke_backend::Artichoke as artichoke_backend::prelude::Intern>::Symbol}
Symbol
index returned by the interner. Read moreSource§fn intern_bytes<T>(
&mut self,
bytes: T,
) -> Result<<Artichoke as Intern>::Symbol, <Artichoke as Intern>::Error>
fn intern_bytes<T>( &mut self, bytes: T, ) -> Result<<Artichoke as Intern>::Symbol, <Artichoke as Intern>::Error>
Source§fn check_interned_bytes(
&self,
bytes: &[u8],
) -> Result<Option<<Artichoke as Intern>::Symbol>, <Artichoke as Intern>::Error>
fn check_interned_bytes( &self, bytes: &[u8], ) -> Result<Option<<Artichoke as Intern>::Symbol>, <Artichoke as Intern>::Error>
None
if the string has not been interned before. Read moreSource§fn lookup_symbol(
&self,
symbol: <Artichoke as Intern>::Symbol,
) -> Result<Option<&[u8]>, <Artichoke as Intern>::Error>
fn lookup_symbol( &self, symbol: <Artichoke as Intern>::Symbol, ) -> Result<Option<&[u8]>, <Artichoke as Intern>::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<(), <Artichoke as Io>::Error>
fn print(&mut self, message: &[u8]) -> Result<(), <Artichoke as Io>::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<(), <Artichoke as LoadSources>::Error>where
P: AsRef<Path>,
T: File<Artichoke = <Artichoke as LoadSources>::Artichoke, Error = <Artichoke as LoadSources>::Exception>,
fn def_file_for_type<P, T>(
&mut self,
path: P,
) -> Result<(), <Artichoke as LoadSources>::Error>where
P: AsRef<Path>,
T: File<Artichoke = <Artichoke as LoadSources>::Artichoke, Error = <Artichoke as LoadSources>::Exception>,
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<(), <Artichoke as LoadSources>::Error>
fn def_rb_source_file<P, T>( &mut self, path: P, contents: T, ) -> Result<(), <Artichoke as LoadSources>::Error>
Source§fn resolve_source_path<P>(
&self,
path: P,
) -> Result<Option<Vec<u8>>, <Artichoke as LoadSources>::Error>
fn resolve_source_path<P>( &self, path: P, ) -> Result<Option<Vec<u8>>, <Artichoke as LoadSources>::Error>
Source§fn source_is_file<P>(
&self,
path: P,
) -> Result<bool, <Artichoke as LoadSources>::Error>
fn source_is_file<P>( &self, path: P, ) -> Result<bool, <Artichoke as LoadSources>::Error>
Source§fn load_source<P>(
&mut self,
path: P,
) -> Result<Loaded, <Artichoke as LoadSources>::Error>
fn load_source<P>( &mut self, path: P, ) -> Result<Loaded, <Artichoke as LoadSources>::Error>
Source§fn require_source<P>(
&mut self,
path: P,
) -> Result<Required, <Artichoke as LoadSources>::Error>
fn require_source<P>( &mut self, path: P, ) -> Result<Required, <Artichoke as LoadSources>::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: <Artichoke as ModuleRegistry>::Spec,
) -> Result<(), <Artichoke as ModuleRegistry>::Error>where
T: Any,
fn def_module<T>(
&mut self,
spec: <Artichoke as ModuleRegistry>::Spec,
) -> Result<(), <Artichoke as ModuleRegistry>::Error>where
T: Any,
T
. Read moreSource§fn module_spec<T>(
&self,
) -> Result<Option<&<Artichoke as ModuleRegistry>::Spec>, <Artichoke as ModuleRegistry>::Error>where
T: Any,
fn module_spec<T>(
&self,
) -> Result<Option<&<Artichoke as ModuleRegistry>::Spec>, <Artichoke as ModuleRegistry>::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<(), <Artichoke as Parser>::Error>
fn reset_parser(&mut self) -> Result<(), <Artichoke as Parser>::Error>
Source§fn fetch_lineno(&self) -> Result<usize, <Artichoke as Parser>::Error>
fn fetch_lineno(&self) -> Result<usize, <Artichoke as Parser>::Error>
Source§fn add_fetch_lineno(
&mut self,
val: usize,
) -> Result<usize, <Artichoke as Parser>::Error>
fn add_fetch_lineno( &mut self, val: usize, ) -> Result<usize, <Artichoke as Parser>::Error>
Source§fn push_context(
&mut self,
context: <Artichoke as Parser>::Context,
) -> Result<(), <Artichoke as Parser>::Error>
fn push_context( &mut self, context: <Artichoke as Parser>::Context, ) -> Result<(), <Artichoke as Parser>::Error>
Source§impl Prng for Artichoke
impl Prng for Artichoke
Source§impl Regexp for Artichoke
impl Regexp for Artichoke
Source§type Error = InterpreterExtractError
type Error = InterpreterExtractError
Regexp
state.Source§fn capture_group_globals(&self) -> Result<usize, <Artichoke as Regexp>::Error>
fn capture_group_globals(&self) -> Result<usize, <Artichoke as Regexp>::Error>
Regexp
capture group global
variables. Read moreSource§impl TryConvert<Seed, Value> for Artichoke
impl TryConvert<Seed, Value> for Artichoke
Source§impl<T, U> TryConvert<T, U> for Artichoke
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, <Artichoke as TryConvert<T, U>>::Error>
fn try_convert( &self, value: T, ) -> Result<U, <Artichoke as TryConvert<T, U>>::Error>
Blanket implementation that always succeeds by delegating to
Convert::convert
.
Source§impl TryConvert<Value, Float> for Artichoke
impl TryConvert<Value, Float> for Artichoke
Source§impl TryConvert<Value, Integer> for Artichoke
impl TryConvert<Value, Integer> for Artichoke
Source§impl TryConvertMut<&mut [Value], Args> for Artichoke
impl TryConvertMut<&mut [Value], Args> for Artichoke
Source§impl<'a> TryConvertMut<&'a mut Value, CaptureExtract<'a>> for Artichoke
impl<'a> TryConvertMut<&'a mut Value, CaptureExtract<'a>> for Artichoke
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 TryConvertMut<CaptureMatch, Value> for Artichoke
impl TryConvertMut<CaptureMatch, Value> for Artichoke
Source§impl<T, U> TryConvertMut<T, U> for Artichokewhere
Artichoke: ConvertMut<T, U>,
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, <Artichoke as TryConvertMut<T, U>>::Error>
fn try_convert_mut( &mut self, value: T, ) -> Result<U, <Artichoke as TryConvertMut<T, U>>::Error>
Blanket implementation that always succeeds by delegating to
Convert::convert
.