pub trait HostFunction<WB: WasmBackend>: Send + Sync + Clone {
// Required methods
fn new<F>(store: &mut impl AsContextMut<WB>, sig: FuncSig, func: F) -> Self
where F: for<'c> Fn(&[WValue]) -> Result<Vec<WValue>> + Sync + Send + 'static;
fn new_with_caller<F>(
store: &mut impl AsContextMut<WB>,
sig: FuncSig,
func: F
) -> Self
where F: for<'c> Fn(<WB as WasmBackend>::ImportCallContext<'c>, &[WValue]) -> Result<Vec<WValue>> + Sync + Send + 'static;
fn new_typed<Params, Results, Env>(
store: &mut impl AsContextMut<WB>,
func: impl IntoFunc<WB, Params, Results, Env>
) -> Self;
fn signature(&self, store: &mut impl AsContextMut<WB>) -> FuncSig;
}
Expand description
A host function ready to be used as an import for instantiating a module.
As it is only a handle to an object in Store
, cloning is cheap.
Required Methods§
sourcefn new<F>(store: &mut impl AsContextMut<WB>, sig: FuncSig, func: F) -> Self
fn new<F>(store: &mut impl AsContextMut<WB>, sig: FuncSig, func: F) -> Self
Creates a new function with dynamic signature. The signature check is performed at runtime.
sourcefn new_with_caller<F>(
store: &mut impl AsContextMut<WB>,
sig: FuncSig,
func: F
) -> Selfwhere
F: for<'c> Fn(<WB as WasmBackend>::ImportCallContext<'c>, &[WValue]) -> Result<Vec<WValue>> + Sync + Send + 'static,
fn new_with_caller<F>(
store: &mut impl AsContextMut<WB>,
sig: FuncSig,
func: F
) -> Selfwhere
F: for<'c> Fn(<WB as WasmBackend>::ImportCallContext<'c>, &[WValue]) -> Result<Vec<WValue>> + Sync + Send + 'static,
Creates a new function with dynamic signature that needs a context.
sourcefn new_typed<Params, Results, Env>(
store: &mut impl AsContextMut<WB>,
func: impl IntoFunc<WB, Params, Results, Env>
) -> Self
fn new_typed<Params, Results, Env>( store: &mut impl AsContextMut<WB>, func: impl IntoFunc<WB, Params, Results, Env> ) -> Self
Creates a new function with static signature. Requires less runtime checks when called.
sourcefn signature(&self, store: &mut impl AsContextMut<WB>) -> FuncSig
fn signature(&self, store: &mut impl AsContextMut<WB>) -> FuncSig
Returns the signature of the function. The signature is constructed each time this function is called, so it is not recommended to use this function extensively.
Object Safety§
This trait is not object safe.