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 toStoreContextMut<'_, T>
and/or get access toT
itself. This means that theCaller
type can serve as a proxy to the originalStore
itself and is used to satisfyAsContext
andAsContextMut
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
sourceimpl<T> Caller<'_, T>
impl<T> Caller<'_, T>
sourcepub fn get_export(&mut self, name: &str) -> Option<Extern>
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.
sourcepub fn data(&self) -> &T
pub fn data(&self) -> &T
Access the underlying data owned by this Store
.
Same as Store::data
sourcepub fn data_mut(&mut self) -> &mut T
pub fn data_mut(&mut self) -> &mut T
Access the underlying data owned by this Store
.
Same as Store::data_mut
sourcepub fn fuel_consumed(&self) -> Option<u64>
pub fn fuel_consumed(&self) -> Option<u64>
Returns the fuel consumed by this store.
For more information see Store::fuel_consumed
sourcepub fn add_fuel(&mut self, fuel: u64) -> Result<()>
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
sourcepub fn consume_fuel(&mut self, fuel: u64) -> Result<u64>
pub fn consume_fuel(&mut self, fuel: u64) -> Result<u64>
Synthetically consumes fuel from the store.
For more information see Store::consume_fuel
sourcepub fn out_of_fuel_trap(&mut self)
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
sourcepub fn out_of_fuel_async_yield(
&mut self,
injection_count: u64,
fuel_to_inject: u64
)
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
sourceimpl<T> AsContext for Caller<'_, T>
impl<T> AsContext for Caller<'_, T>
sourcefn as_context(&self) -> StoreContext<'_, T>
fn as_context(&self) -> StoreContext<'_, T>
Returns the store context that this type provides access to.
sourceimpl<T> AsContextMut for Caller<'_, T>
impl<T> AsContextMut for Caller<'_, T>
sourcefn as_context_mut(&mut self) -> StoreContextMut<'_, T>
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more