Struct wasmtime::Caller

source ·
pub struct Caller<'a, T> { /* private fields */ }
Expand description

A structure representing the caller’s context when creating a function via Func::wrap.

This structure can be taken as the first parameter of a closure passed to Func::wrap or other constructors, and serves two purposes:

  • First consumers can use Caller<'_, T> to get access to StoreContextMut<'_, T> and/or get access to T itself. This means that the Caller type can serve as a proxy to the original Store itself and is used to satisfy AsContext and AsContextMut bounds.

  • Second a Caller can be used as the name implies, learning about the caller’s context, namely it’s exported memory and exported functions. This allows functions which take pointers as arguments to easily read the memory the pointers point into, or if a function is expected to call malloc in the wasm module to reserve space for the output you can do that.

Host functions which want access to Store-level state are recommended to use this type.

Implementations§

source§

impl<T> Caller<'_, T>

source

pub fn get_export(&mut self, name: &str) -> Option<Extern>

Looks up an export from the caller’s module by the name given.

Note that when accessing and calling exported functions, one should adhere to the guidelines of the interface types proposal. This method is a temporary mechanism for accessing the caller’s information until interface types has been fully standardized and implemented. The interface types proposal will obsolete this type and this will be removed in the future at some point after interface types is implemented. If you’re relying on this method type it’s recommended to become familiar with interface types to ensure that your use case is covered by the proposal.

Return

If a memory or function export with the name provided was found, then it is returned as a Memory. There are a number of situations, however, where the memory or function may not be available:

  • The caller instance may not have an export named name
  • The export named name may not be an exported memory
  • There may not be a caller available, for example if Func was called directly from host code.

It’s recommended to take care when calling this API and gracefully handling a None return value.

source

pub fn data(&self) -> &T

Access the underlying data owned by this Store.

Same as Store::data

source

pub fn data_mut(&mut self) -> &mut T

Access the underlying data owned by this Store.

Same as Store::data_mut

source

pub fn engine(&self) -> &Engine

Returns the underlying Engine this store is connected to.

source

pub fn gc(&mut self)

Perform garbage collection of ExternRefs.

Same as Store::gc.

source

pub fn fuel_consumed(&self) -> Option<u64>

Returns the fuel consumed by this store.

For more information see Store::fuel_consumed

source

pub fn add_fuel(&mut self, fuel: u64) -> Result<()>

Inject more fuel into this store to be consumed when executing wasm code.

For more information see Store::add_fuel

source

pub fn consume_fuel(&mut self, fuel: u64) -> Result<u64>

Synthetically consumes fuel from the store.

For more information see Store::consume_fuel

source

pub fn out_of_fuel_trap(&mut self)

Configures this Store to trap whenever fuel runs out.

For more information see Store::out_of_fuel_trap

source

pub fn out_of_fuel_async_yield( &mut self, injection_count: u64, fuel_to_inject: u64 )

Configures this Store to yield while executing futures whenever fuel runs out.

For more information see Store::out_of_fuel_async_yield

Trait Implementations§

source§

impl<T> AsContext for Caller<'_, T>

§

type Data = T

The host information associated with the Store, aka the T in Store<T>.
source§

fn as_context(&self) -> StoreContext<'_, T>

Returns the store context that this type provides access to.
source§

impl<T> AsContextMut for Caller<'_, T>

source§

fn as_context_mut(&mut self) -> StoreContextMut<'_, T>

Returns the store context that this type provides access to.

Auto Trait Implementations§

§

impl<'a, T> !RefUnwindSafe for Caller<'a, T>

§

impl<'a, T> Send for Caller<'a, T>where T: Send,

§

impl<'a, T> Sync for Caller<'a, T>where T: Sync,

§

impl<'a, T> Unpin for Caller<'a, T>

§

impl<'a, T> !UnwindSafe for Caller<'a, T>

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> Pointable for T

source§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
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.
source§

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

source§

fn vzip(self) -> V