Difficulty: beginner
Estimated Time: As long as you need

Deno logo Rust logo

Objective

The objective of this scenario is to demonstrate how to create a WebAssembly binary using the Rust programming language and then exexcute that WebAssembly from within Deno.

Why WebAssembly and Deno are so cool

WebAssembly binaries are by nature faster and more efficient than running interpreted code such at Typescript/Javascript on the server side.

WebAssembly is made for intensive computing. Thus, you can put computationally intensive logic in a WebAssembly binary, but use Deno to do things such as manage workflow, do data access or accommodate request/response traffic. Also, a language such as Rust, which we'll use to create the WebAssembly in this scenario, supports multi-threading. This means you can work with threads, which is not something easily done in Deno. And, your threads will execute in native code. It's a big advantage.

Using Deno to invoke logic represented in a WebAssembly binary created in Rust provides the best of all worlds.

What you will be doing

This scenario already ships with Deno installed. Thus, you will:

  • Install the Rust programming environment
  • Install Rust's WebAssembly compiler
  • Create a WebAssembly binary
  • Create a small program in Deno that uses the WebAssembly binary you created.
  • Run the Deno program

Click the START SCENARIO button to continue.

v.06.27.2020

This project is inspired by an article written by Michael Lazarski (@lampewebdev) that you can read here: https://dev.to/lampewebdev/writing-webassembly-in-rust-and-runing-it-in-deno-144j

Deno logo Rust logo

Congratulations

In this scenario you've learned how to:

  • Install the Rust programming environment
  • Install Rust's WebAssembly compiler
  • Create a WebAssembly binary
  • Create a small program in Deno that uses the WebAssembly binary you created.
  • Run the Deno program

Now take what you've learned and make some amazing code!

Give Credit Where Credit is Due

This project is inspired by an article written by Michael Lazarski (@lampewebdev) that you can read here.

Creating a Rust WebAssembly running under Deno

Step 1 of 5

Install Rust

Rust logo

Objective

The objective of lesson is to demonstrate how to install the Rust programming language on a Ubuntu virtual machine.

A version of Visual Studio Code is embedded in this Katacoda interactive learning environment. Just click the IDE tab at the top of the terminal pane to the right.

Steps

Step 1: Run the following curl command to install Rust.

IMPORTANT: During the Rust installation process you will be asked to select an option. Select option 1.

curl https://sh.rustup.rs -sSf | sh

When you see the prompt to select an option like so...

Current installation options:


   default host triple: x86_64-unknown-linux-gnu
     default toolchain: stable
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation

.. strike the 1 key.

You should see output similar to the following:

Rust is installed now. Great!

Step 2: Set the environment variables required by Rust

source $HOME/.cargo/env

Next Steps

Intalling the WebAssembly compiler for Rust.