pub struct HostFunctions(/* private fields */);Expand description
A collection of host functions that can be supplied to a sandbox
constructor (e.g. MultiUseSandbox::from_snapshot).
A collection of host functions that can be supplied to a sandbox
constructor (e.g. crate::MultiUseSandbox::from_snapshot) to
expose host-side functionality to the guest.
Use HostFunctions::default to start with the standard
HostPrint function pre-registered (matches the registry that the
regular UninitializedSandbox → evolve() path constructs), or
HostFunctions::empty to start with an empty registry.
Add additional host functions via the
crate::func::Registerable trait, just as you would on an
UninitializedSandbox.
// Default: HostPrint already registered.
let mut funcs = HostFunctions::default();
funcs.register_host_function("Add", |a: i32, b: i32| Ok(a + b))?;Implementations§
Source§impl HostFunctions
impl HostFunctions
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Create an empty HostFunctions with no host functions
registered.
Most callers want HostFunctions::default instead, which
pre-registers the standard HostPrint function. An empty
registry will fail snapshot validation against any snapshot
that captured HostPrint, and any guest code that tries to
printf into an empty registry will get an EIO from
write(2).
Trait Implementations§
Source§impl Default for HostFunctions
impl Default for HostFunctions
Source§fn default() -> Self
fn default() -> Self
Create a HostFunctions pre-populated with the standard
HostPrint function (writes UTF-8 strings to the host’s
stdout in green).
This matches the default registry installed by
UninitializedSandbox::new(), so a snapshot taken from a
regular sandbox can be loaded with
MultiUseSandbox::from_snapshot(snap, HostFunctions::default(), None)
without registering anything else.
Use HostFunctions::empty for an empty registry.