This tutorial takes you through all you need to know to compile a Rust project to WebAssembly and then run it in Deno.

Why Rust? Web applications struggle to attain and retain reliable performance. JavaScript’s dynamic type system and garbage collection pauses don’t help. Seemingly small code changes can result in drastic performance regressions if you accidentally wander off the JIT’s (Just In Time Compiler) happy path.

Rust gives programmers low-level control and reliable performance. It is free from the non-deterministic garbage collection pauses that plague JavaScript. Programmers have control over indirection, monomorphization and memory layout.

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. Before we go any further, the following need to be installed on your machine for working with Rust and Deno.

  • rustc: This is the compiler for the Rust programming language, provided by the project itself. Compilers take your source code and produce binary code, either as a library or executable.
  • rustup: This installs the Rust programming language from the official release channels, enabling you to easily switch between stable, beta and nightly compilers and keep them updated.
  • cargo: This is the Rust package manager. Cargo downloads your Rust package’s dependencies, compiles your packages, makes distributable packages and uploads them to crates.io, the Rust community’s package registry.
  • deno: This is a JavaScript/TypeScript runtime with secure defaults and a great developer experience.

#rust #webassembly #deno #javascript #programming

How to Compile Rust into WebAssembly and Run It in Deno
2.25 GEEK