It’s an exciting time for web development right now as new technologies are being widely supported and adopted. We can now easily compile code written in the Rust language into the WebAssembly instruction format. We can then use it natively in web pages and also in JavaScript runtimes like Node.js, or, like we’ll do here, Deno.

Here’s the content we’ll cover, from installing the necessary tools to compile Rust code and the tools to compile it into the WebAssembly format, to finally loading and using the library in Deno. For this tutorial, we’ll assume a macOS environment.

What’s Rust, WebAssembly, and Deno?

Rust is a programming language focused on speed, memory safety, and parallelism. It’s open source and the main backer is Mozilla. It’s being used to build many things from game engines and operating systems to browser components and virtual reality engines. Mozilla actively uses it to build parts of the Firefox browser. Here’s a short intro video:

As cool as Rust is, it’s not something we can run directly in the browser or in a JavaScript runtime. Enter WebAssembly. It’s a binary instruction format for a stack-based virtual machine that aims to run in the browser at native speed and is sandboxed for security. The JavaScript API, that we’ll use later, provides a method to interact between the two.

And finally, Deno, the new JavaScript runtime, which is great to run WebAssembly because it has native support for its binaries and can use them following the JavaScript API mentioned before.

#javascript #development #rust #webassembly #deno

How to Compile Rust to WebAssembly and run it in Deno
11.90 GEEK