Go to content

Underrated gems of Rust & WebAssembly: Errors, Async, I/O - Alberto Schiabel

WebAssembly has revolutionised cross-platform development, enabling developers to compile their code just once, regardless of the runtime operating system or CPU architecture. While Rust boasts the best language support for WebAssembly through the wasm-bindgen tool, developers often encounter unexpected challenges and differences in execution models. Similarly to no_std, not every Rust code can be compiled to Wasm out of the box. For example, in a Rust library compiled to Wasm, panics cannot be unwinded (and their stacktrace location is lost), and async functions à la tokio cannot be awaited. Moreover, no I/O operation can be performed in WebAssembly: that means no network connections nor file handles can be opened. The WASI specification partially overcomes this limitation, but that’s still unstable and doesn’t cover network sockets. What if you wanted to write a production async Rust library that needs both robust error handling and I/O, and you needed to run it in JavaScript runtimes like Node.js? In this talk, we will explore uncharted territories in Wasm land, where you’ll learn how to confidently integrate your familiar Rust patterns with powerful - but fragile - WebAssembly runtimes. As a motivating example, we will present a database query engine prototype written in Rust+Wasm that accepts a JSON query, parses it into an equivalent SQL query, runs such query asynchronously and returns the results to the caller. Just like pirates in a sea of compilation errors, we will bend the rules to conquer new horizons in the realm of truly cross-platform Rust libraries! 🦀 *About Alberto Schiabel* 🦀 Alberto Schiabel (https://twitter.com/jkomyno) is a senior software engineer, consultant, and former startup co-founder from Venice, Italy. He has 8+ years of industry experience, and is interested in WebAssembly. He’s currently an open-source engineer at Prisma, where he mainly writes in Rust and TypeScript. He also writes scientific software for the Czech Technical University in Prague.

October 10, 2023