Skip to main content

Registerable

Trait Registerable 

Source
pub trait Registerable {
    // Required method
    fn register_host_function(&mut self, fn_id: u32, func: HostFn) -> Result<()>;
}
Expand description

A sandbox on which host functions can be registered.

Required Methods§

Source

fn register_host_function(&mut self, fn_id: u32, func: HostFn) -> Result<()>

Register func to be invoked by the guest under the given fn_id. Overwrites any prior entry for that id.

Implementors§

Source§

impl Registerable for MultiUseSandbox

Allow registering host functions on an already-evolved crate::MultiUseSandbox.

The primary entry point for host-function registration is the UninitializedSandbox impl above — that’s the lifecycle phase where the guest hasn’t yet been allowed to issue host calls. There are, however, cases where a MultiUseSandbox is obtained without traversing the Uninitialized → evolve() path:

  • Sandboxes loaded from a persisted snapshot.
  • Any future API that yields a MultiUseSandbox directly.

In those cases the caller never had a chance to call register_host_function on an UninitializedSandbox, so we expose the same trait implementation here for late registration. The guest’s dispatcher resolves by fn_id at call time, so inserting into the registry after evolve() is semantically safe as long as the first host-function invocation happens after registration completes.

Source§

impl Registerable for UninitializedSandbox