Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon

How has Rust and WebAssembly evolved in 2018

Save for later
  • 3 min read
  • 07 Dec 2018

article-image

In a blog post, the state of Rust and WebAssembly for 2018 was discussed by the Rust-Wasm team. The Rust and WebAssembly domain working group worked to make a shared vision into a reality: “Compiling Rust to WebAssembly should be the best choice for fast, reliable code for the Web.

With the evolution of ideas, another core value was formed: “Rust and WebAssembly is here to augment your JavaScript, not replace it.

Goals were set for the joint ecosystem.

#1 JavaScript interoperation with zero-cost


By leveraging zero-cost abstractions Rust enables fast and expressive code. The Rust team wanted to apply this principle to the whole JS interop infrastructure. Developers can write their own boilerplate to pass DOM nodes to wasm generated by Rust but that shouldn’t be the case.

Hence they created wasm-bindgen as the foundation for JavaScript interoperation with zero cost. The communication between JavaScript and WebAssembly is facilitated by wasm-bindgen. This generates glue code which developers would have had to write themselves.

With the wasm-bindgen ecosystem helps developers to:

  • Exporting rich APIs from Rust-generated wasm libraries. This makes them callable from JavaScript.
  • Import JavaScript and Web APIs into the Rust-generated wasm.

#2 Rust-Generated Wasm as an NPM library


Good integration is about fitting Rust-generated WebAssembly into the JavaScript’s distribution mechanisms. A big part of that is NPM. The Rust team built a wasm-pack to creating and publishing NPM packages from Rust and WebAssembly code. Sharing Rust-generated wasm modules is now as simple as:

wasm-pack publish

#3 To get developers productive fast


The Rust team wrote a Rust and WebAssembly book to teach all the ins and outs of WebAssembly development with Rust. It features a tutorial to build an implementation of the Conway's Game of Life and teaches you how to write tests, debugging, and diagnosing slow code paths.

Getting a Rust-WebAssembly project set up initially involves a boilerplate and configuration that new users may find difficult or experienced ones may find as a waste of time. Hence the Rust team has created a variety of project templates for different use cases:

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
  • wasm-pack-template to create NPM libraries with Rust and Wasm.
  • create-wasm-app to create Web applications built on top of Rust-generated wasm NPM libraries.
  • rust-webpack-template to create whole Web applications with Rust, WebAssembly, and the Webpack bundler.
  • rust-parcel-template to create whole Web applications with Rust, WebAssembly, and the Parcel bundler.

#4 Rust-Generated Wasm needs to be testable and debuggable


wasm can’t log any panics or errors because by default as it doesn’t have any “syscall” or I/O functionality. Imports have to be manually added for that, and then instantiate the module with appropriate functions. To remedy this, and to ensure that panics are always debuggable, the Rust team created the console_error_panic_hook crate. It redirects panic messages into the browser’s devtools console.

For more details on the state of the joint ecosytem in 2018, visit the Rust and WebAssembly Blog.

Mozilla shares plans to bring desktop applications, games to WebAssembly and make deeper inroads for the future web

Red Hat announces full support for Clang/LLVM, Go, and Rust

WebAssembly – Trick or Treat?