Struct wasmedge_sdk::Caller

source ·
pub struct Caller { /* private fields */ }
Expand description

Represents the calling frame on top of stack.

The Caller object is only used as the first argument when defining a host function. With this argument, developers can have access to the Executor instance, the Instance instance, and the Memory instance inside the host functions they defined.

Implementations§

source§

impl Caller

source

pub fn new(frame: CallingFrame) -> Self

Creates a Caller instance with the given CallingFrame instance.

Caller vs. CallingFrame

CallingFrame is a low-level type defined in wasmedge-sys crate, while Caller is a high-level type. For developers using the APIs in wasmedge-sdk, they should create a Caller instance with the given CallingFrame instance, as Caller provides APIs to access high-level instances, such as executor and memory, related to the current calling frame.

source

pub fn executor(&self) -> Option<&Executor>

Returns the executor instance from this caller.

source

pub fn executor_mut(&mut self) -> Option<&mut Executor>

Returns the mutable executor instance from this caller.

source

pub fn instance(&self) -> Option<&Instance>

Returns the module instance in this caller.

source

pub fn instance_mut(&mut self) -> Option<&mut Instance>

Returns the mutable module instance in this caller.

source

pub fn memory(&self, idx: u32) -> Option<Memory>

Returns the memory instance by the given index from the module instance of this caller. If the memory instance is not found, then return None.

Arguments
  • idx - The index of the memory instance. By default, a WASM module has only one memory instance after instantiation. Therefore, users can pass in 0 as the index to get the memory instance in host function body. When the MultiMemories config option is enabled, there would be more than one memory instances in the wasm module. Users can retrieve the target memory instance by specifying the index of the memory instance in the wasm module instance.

Trait Implementations§

source§

impl Debug for Caller

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<CallingFrame> for Caller

source§

fn from(frame: CallingFrame) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Caller

§

impl Send for Caller

§

impl Sync for Caller

§

impl Unpin for Caller

§

impl !UnwindSafe for Caller

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V