WebAssembly Modules in Rust: Syntax Deep Dive

Exploring features, compilation and dependencies of a Rust wasm module

Ross Bulat
10 min readSep 28, 2019

This is a continuation of the previous article that introduced developing WebAssembly modules in Rust, where the demo project (hosted on Github) showcases an asynchronous fetch request called directly within Rust code and the compiled wasm binary.

Where the introductory article covered the process of developing and building a WebAssembly module, here we will explore the syntax of the project in more detail to understand how the project is constructed in Rust. The concepts covered here will surely be helpful if you are a web developer exploring the Rust programming language for use with WebAssembly modules, or studying Rust use cases in general.

More specifically, we will visit concepts including:

  • How Cargo and conditional compilation have been used to include a WebAssembly specific debugging tool for the browser
  • How the use of FFI (Foreign Function Interfaces) are used to link Javascript and Rust functions
  • How Rust deals with asynchronous functions and Javascript Promise objects with Rust Futures and utilities from web-sys and js-sys crates.

--

--

Ross Bulat

Programmer and Author. @ Parity Technologies, JKRB Investments