referrerpolicy=no-referrer-when-downgrade

Trait sp_wasm_interface::HostFunctionRegistry

source ·
pub trait HostFunctionRegistry {
    type State;
    type Error;
    type FunctionContext: FunctionContext;

    // Required methods
    fn with_function_context<R>(
        caller: Caller<'_, Self::State>,
        callback: impl FnOnce(&mut dyn FunctionContext) -> R,
    ) -> R;
    fn register_static<Params, Results>(
        &mut self,
        fn_name: &str,
        func: impl IntoFunc<Self::State, Params, Results> + 'static,
    ) -> Result<(), Self::Error>;
}
Expand description

A trait used to statically register host callbacks with the WASM executor, so that they call be called from within the runtime with minimal overhead.

This is used internally to interface the wasmtime-based executor with the host functions’ definitions generated through the runtime interface macro, and is not meant to be used directly.

Required Associated Types§

Required Methods§

source

fn with_function_context<R>( caller: Caller<'_, Self::State>, callback: impl FnOnce(&mut dyn FunctionContext) -> R, ) -> R

Wraps the given caller in a type which implements FunctionContext and calls the given callback.

source

fn register_static<Params, Results>( &mut self, fn_name: &str, func: impl IntoFunc<Self::State, Params, Results> + 'static, ) -> Result<(), Self::Error>

Registers a given host function with the WASM executor.

The function has to be statically callable, and all of its arguments and its return value have to be compatible with WASM FFI.

Object Safety§

This trait is not object safe.

Implementors§