Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon

Rust and Web Assembly announce ‘wasm-bindgen 0.2.16’ and the first release of ‘wasm-bindgen-futures’

Save for later
  • 3 min read
  • 14 Aug 2018

article-image

Yesterday, the Rust and Web Assembly community made two announcements. Firstly, it released the ‘wasm-bindgen 0.2.16 version and second, it published the first release of ‘wasm-bindgen-futures’.

wasm-bindgen facilitates high-level communication between JavaScript and Rust compiled to WebAssembly. It allows one to speak in terms of Rust structs, JavaScript classes, strings, etc.,instead of only the integers and floats supported by WebAssembly’s raw calling convention.

The wasm-bindgen is designed to support the upcoming “Host Bindings” proposal, which will eliminate the need for any kind of JavaScript shim functions between WebAssembly functions and native DOM functions.

What’s new in wasm-bindgen 0.2.16

Added features

  • Added the wasm_bindgen::JsCast trait, as described in RFC #2.
  • Added support for receiving Option<&T> parameters from JavaScript in exported Rust functions and methods and for receiving Option<u32> and other option-wrapped scalars.
  • Added reference documentation to the guide for every #[wasm_bindgen] attribute and how it affects the generated bindings.

Changes in this version 0.2.16

  • Restructured the guide's documentation on passing JS closures to Rust, and Rust closures to JS. Also improved  the guide's documentation on using serde to serialize complex data to JsValue and deserialize JsValues back into complex data.
  • Unlock access to the largest independent learning library in Tech for FREE!
    Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
    Renews at $19.99/month. Cancel anytime
  • Static methods are now always bound to their JS class, as is required for Promise's static methods.

The newly released wasm-bindgen-futures


The wasm-bindgen-futures is a crate that bridges the gap between a Rust Future and a JavaScript Promise. It provides two conversions:

  • From a JavaScript Promise into a Rust Future.
  • From a Rust Future into a JavaScript Promise.


The two main interfaces in this crate are:

JsFuture


The JsFuture is constructed with a Promise and can then be used as a Future<Item = JsValue, Error = JsValue>. This Rust future will resolve or reject with the value coming out of the Promise

Future_to_promise


Future_to_promise interface converts a Rust Future<Item = JsValue, Error = JsValue> into a JavaScript Promise. The future's result will translate to either a rejected or resolved Promise in JavaScript.

These two items provide enough of a bridge to interoperate the two systems and make sure that Rust/JavaScript can work together with asynchronous and I/O work.

To know more about wasm-bindgen version 0.2.16 and wasm-bindgen-futures visit its GitHub page.

Warp: Rust’s new web framework for implementing WAI (Web Application Interface)

Rust 1.28 is here with global allocators, nonZero types and more

Say hello to Sequoia: a new Rust based OpenPGP library to secure your apps