expression
Export a scalar Rust function for a minimal Wasm host
A cdylib targeting wasm32-unknown-unknown can expose a scalar function under an explicit symbol name. This source is a real Rust build candidate, not a hosted main program. Build and verify with the Rust target lab. The fixed-width scalar boundary avoids allocation ownership and string conversion. Expected add(20, 22) = 42; wrapping behavior is explicit. No arbitrary host capabilities are granted. Wasm build candidate; expected export result is verified only after the separate Rust target lab runs. Common mistake: Exporting a Rust String by value as though it were a stable host ABI.
Formal Syntax & Structure
rust syntaxrust
#[unsafe(no_mangle)] pub extern "C" fn ...Working Example
Example Snippetrust
// SAFETY: this standalone module reserves the unique exported symbol bm_add.#[unsafe(no_mangle)]pub extern "C" fn bm_add(a: u32, b: u32) -> u32 { a.wrapping_add(b) }