wasm-bindgen /wasm-bindgen

Facilitating high-level interactions between Wasm modules and JavaScript

★ 9,228⑂ 1,265👁 93⑃ 2,946● 2,306▤ 133
RustApache-2.0Created 2017-12-18wasm-bindgen.github.io/wasm-bindgen/
下载:0.2.1300.2.130 ↓0.2.1302026-10-30
+1
日增长
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

Discussions

Latest release

0.2.130 0.2.130 2026-10-30
Added

 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

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON