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.
The wasm-bindgen-futures is a crate that bridges the gap between a Rust Future and a JavaScript Promise. It provides two conversions:
The two main interfaces in this crate are:
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 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