2 min read

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 parameters from JavaScript in exported Rust functions and methods and for receiving Option 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.
  • 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. 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 Futureinto 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.

Read Next

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


Subscribe to the weekly Packt Hub newsletter. We'll send you the results of our AI Now Survey, featuring data and insights from across the tech landscape.

A Data science fanatic. Loves to be updated with the tech happenings around the globe. Loves singing and composing songs. Believes in putting the art in smart.

LEAVE A REPLY

Please enter your comment!
Please enter your name here