2 min read

Mozilla is building a bridge between Rust and JavaScript. The bridge – Wasm-bindgen – allows Rust to interact with Web Assembly modules and JavaScript. One of Mozilla’s aims is to turn Rust into a language for web development; building a link to WebAssembly is perhaps the most straightforward way for it to run on the web. But this doesn’t mean Mozilla wants Rust to replace JavaScript – far from it. The plan is instead for Rust to be a language that runs alongside JavaScript on the backend.

Read more about Mozilla’s plan here.

What is wasm-bindgen?

It’s worth reading this from the Mozilla blog to see the logic behind wasm-bidgen and how it’s going to work:

“Today the WebAssembly specification only defines four types: two integer types and two floating-point types. Most of the time, however, JS and Rust developers are working with much richer types! For example, JS developers often interact with document to add or modify HTML nodes, while Rust developers work with types like Result for error handling, and almost all programmers work with strings.

Being limited only to the types that WebAssembly provides today would be far too restrictive, and this is where wasm-bindgen comes into the picture. The goal of wasm-bindgen is to provide a bridge between the types of JS and Rust. It allows JS to call a Rust API with a string, or a Rust function to catch a JS exception. wasm-bindgen erases the impedance mismatch between WebAssembly and JavaScript, ensuring that JavaScript can invoke WebAssembly functions efficiently and without boilerplate, and that WebAssembly can do the same with JavaScript functions.”

This is exciting as it is a valuable step in expanding the capabilities of Rust. But the thinking behind wasm-bindgen will also help to further drive the adoption of web assembly. While the focus is, of course, on Rust at the moment, there’s a possibility that wasm-bindgen could eventually be used with other languages, such as C and C++. This might take some time, owever.

Download wasm-bindgen from GitHub.

Co-editor of the Packt Hub. Interested in politics, tech culture, and how software and business are changing each other.


Please enter your comment!
Please enter your name here