Skip to main content

HostFunctionProvider

Trait HostFunctionProvider 

Source
pub trait HostFunctionProvider<T> {
    // Required method
    fn register(
        &self,
        builder: &mut HostLinkerBuilder<'_, T>,
    ) -> Result<(), LinkerError>;
}
Expand description

Trait for types that provide host functions.

Implement this to create reusable sets of host functions that can be registered with multiple instances.

§Example

struct LoggingProvider;

impl HostFunctionProvider<MyState> for LoggingProvider {
    fn register(&self, builder: &mut HostLinkerBuilder<'_, MyState>) -> Result<(), LinkerError> {
        builder.interface("logging")?
            .func_raw("log", |caller, ptr, len| { ... })?;
        Ok(())
    }
}

Required Methods§

Source

fn register( &self, builder: &mut HostLinkerBuilder<'_, T>, ) -> Result<(), LinkerError>

Register this provider’s functions with the linker builder.

Implementors§