wasm-bindgen
Core Rust library and CLI tool for facilitating high-level interactions between Rust/WebAssembly and JavaScript. The #[wasm_bindgen] macro generates JavaScript glue code that allows calling Rust functions from JavaScript and vice versa. Handles type conversion, memory management, and DOM access. The foundation for all Rust-to-browser compilation workflows, used by wasm-pack to build npm packages from Rust.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
WASM sandbox provides memory isolation. Rust memory safety prevents buffer overflows and use-after-free. Generated JS glue code handles type coercion safely.
⚡ Reliability
Best When
You have performance-critical code in Rust that needs to run in the browser, or you're building a Rust+WASM npm package for JavaScript consumption.
Avoid When
You're targeting server-side execution, don't need browser interop, or want a simpler WASM toolchain — check AssemblyScript or Emscripten for other languages.
Use Cases
- • Compile Rust code to WebAssembly and call it from JavaScript/TypeScript with automatic type bindings generated
- • Expose Rust functions and types to JavaScript with #[wasm_bindgen] annotations for performance-critical browser code
- • Call browser APIs (fetch, DOM, Canvas, WebGL) from Rust code using the web-sys and js-sys crates
- • Build npm packages from Rust code using wasm-pack that work in Node.js, browsers, and bundlers
- • Port compute-intensive Rust algorithms to the browser without rewriting in JavaScript
Not For
- • Server-side Rust — wasm-bindgen targets browser/WebAssembly environments specifically; use standard Rust for servers
- • Node.js-only usage without browser DOM needs — consider NAPI-RS for native Node.js addons instead
- • Teams without Rust experience — the learning curve is significant; consider AssemblyScript for simpler WASM
Interface
Authentication
Build toolchain library. No authentication required.
Pricing
Apache 2.0 and MIT dual license. Part of the Rust WebAssembly working group.
Agent Metadata
Known Gotchas
- ⚠ wasm-bindgen version in Cargo.toml must exactly match wasm-bindgen-cli version — version mismatch causes cryptic 'schema version mismatch' errors at runtime
- ⚠ All types passed across JS/Rust boundary must be #[wasm_bindgen] compatible — complex Rust types need custom serialization (serde-wasm-bindgen or wasm-bindgen JsValue)
- ⚠ Panics in Rust WASM code cause the WASM module to abort and become unusable for the session — must catch all potential panics
- ⚠ Memory is not automatically managed across JS/Wasm boundary — Rust objects passed to JS must be explicitly .free()'d in JavaScript or memory leaks occur
- ⚠ COOP/COEP headers required for SharedArrayBuffer (needed for multi-threading with wasm-bindgen-rayon) — same cross-origin isolation constraint as WebContainers
- ⚠ wasm-pack is the recommended build tool for npm packages — using wasm-bindgen CLI directly requires manual bundler configuration
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for wasm-bindgen.
Scores are editorial opinions as of 2026-03-06.