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.”
Goals were set for the joint ecosystem.
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.
With the wasm-bindgen ecosystem helps developers to:
#2 Rust-Generated Wasm as an NPM library
#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:
- 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.