Struct NativeFunctionContext

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

The input parameter to native Spore VM functions registered with Vm::with_native_function.

fn my_magic_string(ctx: spore_vm::val::NativeFunctionContext) -> spore_vm::error::VmResult<spore_vm::val::ValBuilder> {
    Ok(ctx.new_string("42".into()))
}

Implementations§

Source§

impl<'a> NativeFunctionContext<'a>

Source

pub fn vm(&self) -> &Vm

Get the underlying VM.

Source

pub unsafe fn vm_mut(&mut self) -> &mut Vm

Get a mutable reference to the underlying VM.

§Safety

Any operations that triger GC or evaluation will cause undefined behavior.

Source§

impl<'a> NativeFunctionContext<'a>

Source

pub unsafe fn with_unsafe_val(self, val: UnsafeVal) -> ValBuilder<'a>

Create a new value from an internal.

Consumes the self to ensure that the value isn’t garbage collected.

§Safety

InternalVal must be a valid value that has not been garbage collected.

Source

pub fn new_string(self, s: CompactString) -> ValBuilder<'a>

Create a new string value.

Consumes self to ensure that the value isn’t garbage collected.

fn my_magic_string(ctx: spore_vm::val::NativeFunctionContext) -> spore_vm::error::VmResult<spore_vm::val::ValBuilder> {
    Ok(ctx.new_string("42".into()))
}
Source

pub unsafe fn new_mutable_box(self, v: Val<'a>) -> ValBuilder<'a>

Create a new box from the unsafe val.

Consumes the self to ensure that the value isn’t garbage collected.

§Safety

v must be a valid value within the vm.

Source

pub unsafe fn new_list(self, list: &[Val<'_>]) -> ValBuilder<'a>

Create a new list from ListVal.

Consumes the self to ensure that the value isn’t garbage collected.

§Safety

list must contain valid values within the vm.

Source

pub unsafe fn new_struct(self, strct: StructVal) -> ValBuilder<'a>

Create a new struct from StructVal.

Consumes the self to ensure that the value isn’t garbage collected.

§Safety

strct must contain valid values within the vm.

Source

pub fn new_custom(self, obj: impl CustomType) -> ValBuilder<'a>

Create a new custom value from obj.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.