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§

source

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,

Creates a new function with dynamic signature. The signature check is performed at runtime.

source

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,

Creates a new function with dynamic signature that needs a context.

source

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.

source

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.

Implementors§