expression

Export a Rust function using wasm-bindgen

The attribute generates metadata and binding code so JavaScript can call a supported Rust signature through generated glue. The crate and matching CLI are separate tools. This function doubles small unsigned values and saturates at the maximum instead of overflowing. Expected result (NOT RUN): double_count(21) returns 42; double_count(4294967295) returns 4294967295. Common mistake: Calling an arbitrary Rust ABI function as though its signature automatically maps to JavaScript. Static Rust source module for the accompanying Cargo lab; not a standalone executable or ByteMind exercise.

Formal Syntax & Structure

rust syntaxrust
#[wasm_bindgen] pub fn name(...) -> ...

Working Example

Example Snippetrust
use wasm_bindgen::prelude::*;#[wasm_bindgen]pub fn double_count(n: u32) -> u32 { n.saturating_mul(2) }
Rust Reference