Svelte Wasi With Rust screenshot

Svelte Wasi With Rust

Author Avatar Theme by Happybeing
Updated: 24 Jan 2021
28 Stars

Svelte Rust/WASI in Browser Example

Overview

This product analysis is for a Svelte Rust/WASI in Browser Example. The example uses Rust Web Assembly compiled for WASI (the Web Assembly System Interface) running in the browser using WasmerJS. It also utilizes wasm-bindgen to make it easy to pass data from JavaScript to Rust and vice versa.

Features

  • A Svelte WASM/WASI app with Rust subsystem (using target wasm32-wasi)
  • JavaScript and Rust both accessing the WasmerJS/wasmFS filesystem
  • Calling Rust from JavaScript and vice versa using wasm-bindgen
  • Passing and returning JavaScript and Rust native types with no mucking about
  • Passing and returning JavaScript objects and arrays to/from Rust structs

Installation

To install the Svelte Rust/WASI example, follow these steps:

  1. Make sure you have Rust installed on your machine.
  2. Clone the repository using the following command:
    git clone [repository-url]
    
  3. Navigate to the project directory:
    cd svelte-rust-wasi-example
    
  4. Build the Rust code and generate the Web Assembly file:
    wasm-pack build --target wasm32-wasi
    
  5. Install the necessary dependencies using npm:
    npm install
    
  6. Start the development server:
    npm run dev
    
  7. Open your browser and navigate to http://localhost:5000 to see the Svelte Rust/WASI app running.

Summary

The Svelte Rust/WASI in Browser Example demonstrates how to use Rust Web Assembly compiled for WASI in a browser environment using WasmerJS. It provides seamless integration between JavaScript and Rust with the help of wasm-bindgen. The example showcases various features such as accessing the WasmerJS/wasmFS filesystem, calling functions between JavaScript and Rust, and passing different types of data. The installation process outlined above allows users to set up and run the example on their local machines.