expression
Model an explicitly supplied host function
A Wasm module can declare imported functions; the host supplies compatible implementations when instantiating it. Availability of a host API is not guaranteed by the Rust standard library. The closure model demonstrates injection of a simple arithmetic callback, not an actual Wasm import. Expected host stdout (not executed): result: 9 Common mistake: Assuming the guest can use arbitrary host APIs without an explicit interface.
Formal Syntax & Structure
rust syntaxrust
host: impl Fn(u32) -> u32Working Example
Example Snippetrust
fn guest(value: u32, host: impl Fn(u32) -> u32) -> u32 { host(value) + 1 }fn main() { println!("result: {}", guest(4, |n| n * 2)); }