HostFunction

Trait HostFunction 

Source
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_with_caller_async<F>(
        store: &mut impl AsContextMut<WB>,
        sig: FuncSig,
        func: F,
    ) -> Self
       where F: for<'c> Fn(<WB as WasmBackend>::ImportCallContext<'c>, &'c [WValue]) -> BoxFuture<'c, Result<Vec<WValue>>> + Sync + Send + 'static;
    fn new_async<F>(
        store: &mut impl AsContextMut<WB>,
        sig: FuncSig,
        func: F,
    ) -> Self
       where F: for<'c> Fn(&'c [WValue]) -> BoxFuture<'c, 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_with_caller_async<F>( store: &mut impl AsContextMut<WB>, sig: FuncSig, func: F, ) -> Self
where F: for<'c> Fn(<WB as WasmBackend>::ImportCallContext<'c>, &'c [WValue]) -> BoxFuture<'c, Result<Vec<WValue>>> + Sync + Send + 'static,

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

Source

fn new_async<F>( store: &mut impl AsContextMut<WB>, sig: FuncSig, func: F, ) -> Self
where F: for<'c> Fn(&'c [WValue]) -> BoxFuture<'c, 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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§