wasm-bindgen /wasm-bindgen
Facilitating high-level interactions between Wasm modules and JavaScript
★ 9,228⑂ 1,265👁 93⑃ 2,946● 2,306▤ 133
+1
Daily
9,228
stars
1,265
forks
93
watchers
2,946
prs
2,306
issues
133
releases
README
wasm-bindgen
Facilitating high-level interactions between Wasm modules and JavaScript.
Guide (main branch)
|
API Docs
|
Contributing
|
Chat
Built with 🦀🕸 by The Rust and WebAssembly Working Group
Install wasm-bindgen-cli
You can install it using cargo install:
cargo install wasm-bindgen-cli
Or, you can download it from the
release page.
If you have cargo-binstall installed,
then you can install the pre-built artifacts by running:
cargo binstall wasm-bindgen-cli
Example
Import JavaScript things into Rust and export Rust things to JavaScript.
rust
use wasm_bindgen::prelude::;
// Import the window.alert function from the Web.
[wasm_bindgen]
extern "C" {
fn alert(s: &str);
}
// Export a greet function from Rust to JavaScript, that alerts a
// hello message.
[wasm_bindgen]
pub fn greet(name: &str) {
alert(&format!("Hello, {}!", name));
}
Use exported Rust things from JavaScript with ECMAScript modules!
js
import { greet } from "./hello_world";
greet("World!");
Features
Lightweight. Only pay for what you use. wasm-bindgen only generates
bindings and glue for the JavaScript imports you actually use and Rust
functionality that you export. For example, importing and using the
document.querySelector method doesn't cause Node.prototype.appendChild or
window.alert to be included in the bindings as well.
ECMAScript modules. Just import WebAssembly modules the same way you would
import JavaScript modules. Future compatible with [WebAssembly modules and
ECMAScript modules integration][wasm-es-modules].
Designed with the ["Web IDL bindings" proposal][webidl-bindings] in mind.
Eventually, there won't be any JavaScript shims between Rust-generated wasm
functions and native DOM methods. Because the Wasm functions are statically
type checked, some of those native methods' dynamic type checks should become
unnecessary, promising to unlock even-faster-than-JavaScript DOM access.
[wasm-es-modules]: https://github.com/WebAssembly/esm-integration
[webidl-bindings]: https://github.com/WebAssembly/proposals/issues/8
Guide
📚 Read the wasm-bindgen guide here! 📚
API Docs
- wasm-bindgen
- js-sys
- web-sys
- wasm-bindgen-futures
MSRV Policy
Libraries that are released on crates.io have a MSRV of v1.81.
CLI tools and their corresponding support libraries have a MSRV of v1.86.
The project aims to maintain a 2-year MSRV policy for libraries (meaning we support Rust versions released within the last 2 years), but with a shorter MSRV policy for the CLI. Changes to the MSRV may be made in patch versions, and will be logged in the CHANGELOG and MSRV history below.
MSRV History
| Version | Library MSRV | CLI MSRV | Date |
|---------|--------------|----------|------------|
| 0.2.129 | 1.81 | 1.86 | 2026-09-23 |
| 0.2.118 | 1.77 | 1.86 | 2026-04-10 |
| 0.2.106 | 1.71 | 1.82 | 2025-11-27 |
| Top issues
#3421WASI support47 comments · 2023-05-11#1818Automatically camelify names32 comments · 2019-10-16#2407Support enum variants with values29 comments · 2020-12-29#3939Splitting into multiple lazily-loaded modules28 comments · 2024-04-27#2200memory import undefined22 comments · 2020-06-12#1362Return integers from `charCodeAt` and `codePointAt`21 comments · 2019-03-18#122Allow returning fixed-size tuples and arrays21 comments · 2018-04-12#2231Downcast a JsValue to an exported struct18 comments · 2020-07-09
Discussions
#5469Setting priority on a web_sys Request1 comments · 2026-11-12#5195Proposal: emit `Uint8Array<ArrayBuffer>` in generated TypeScript for owned `Vec<u8>` returns (opt-in)2 comments · 2026-06-11#5098Use async js function in non async rust code1 comments · 2026-04-08#5061Documentation re:weak-ref and finalizers3 comments · 2026-03-26#5017Compilation/Generation Performance with wasm-bindgen-cli0 comments · 2026-03-01#4948Full WASM process memory dumped to OPFS on iOS2 comments · 2026-02-10#4895Consolidating test output for headless browser capture mode0 comments · 2026-01-09#4884`Promise::then`'s `Closure` return type missing?1 comments · 2025-12-30
Latest release
0.2.130 0.2.130 2026-10-30Added A borrowed number, bool, char or borrowed string crosses by copy, so &f64, &Option, &Nullable, Option and Option are argument types, and an experimental_generic_mono import taking &T accepts T = f64, Option or Nullable, as std's contains(&T) does. 5436 Added a rejection type parameter to js_sys::Promise, mirrored on JsFuture, PromiseState and PromiseWithResolvers. Awaiting a Promise yields Result, converting the rejection reason as an E the same unchecked way the fulfilled value is converted as a T. Both parameters are covariant under Upcast; catch, then_with_reje