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 using existing source code
  • Autogenerate the TypeScript and JavaScript adapter code that will consume the WebAssembly binary
  • Execute a small program in Deno that uses the WebAssembly binary you created.

Executing command line instructions

This scenario is completely interactive. The instructions you'll be given will be executed directly in the terminal window that is embedded directly in the Katacoda interactive learning environment. In the steps to come, when you see a command line instruction with a black background and check mark at the end, like so:

Katacoda command line

just click on it and the command will execute in the interative terminal window.

Click the START SCENARIO button to continue.

v.02.09.2021

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
  • Run the Deno program

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

Creating a Rust WebAssembly running under Deno

Step 1 of 4

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: Wait for the Deno programming environment to be installed. You'll know that the enviornment is ready when you see a command prompt, like so, $.

Step 2: 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 3: Set the environment variables required by Rust

source $HOME/.cargo/env


Next Steps

Intalling the WebAssembly compiler for Rust.