Published On: January 22nd, 2023Categories: AI News

It is a universal binary code that is designed for the web.

Wasm uses a low virtual machine with linear memory. It executes safely inside the sandbox.

Wasm Chain

Image Source :→ Tapadoo



When should we use WASM?

Whenever we need to do the heavy computation, we should use wasm as they are efficient and fast.



But why Rust?

You can choose any language that you wish to, but Rust provides low-level control over the memory and is free from non-deterministic garbage collection.



Let’s create our Fibonacci wasm package



1. Creating/ Initializing our first lib

Make sure rust is installed. You can install it from here if not installed.

$  cargo new fibonacci-wasm --lib
Enter fullscreen mode

Exit fullscreen mode



2. Writing our Fibonacci function in Rust

It’s pretty easy to write a function.

pub fn fibonacci(n: i64) -> i64 {
    if n == 0 {
        return 0;
    } else if n == 1 {
        return...

Source link

Leave A Comment