rwasm

Crates.iorwasm
lib.rsrwasm
version0.0.1
sourcesrc
created_at2020-12-19 15:43:29.784172
updated_at2022-08-29 12:27:22.614279
descriptionMinimalistic WASM library
homepagehttps://github.com/rellfy/rwasm
repositoryhttps://github.com/rellfy/rwasm
max_upload_size
id324584
size20,651
Lorenzo Fontoura (rellfy)

documentation

README

rwasm

Github actions Crate version NPM version License

A minimalistic WASM library for Rust.

Core concepts

Remote Procedure Call

All user-defined communication from Rust to Javascript happens via remote procedure calls. The RPCs to be executed are given to the rwasm JS instance as regular functions expecting a single Uint8Array parameter. The user may send the name of the function to be executed along with the data as bytes. There are two types of RPCs that can be executed through rwasm, described below.

"send" RPC

The send RPC type sends data to Javascript and does not expect to receive anything back.

"request" RPC

The request RPC type sends data to Javascript and expects to receive back an usize value. The usize value represents the length of the data, in bytes, written to a Buffer identified by an u32 value, which must be given as a parameter in the request RPC.

Data buffers

The rwasm library defines a hashmap of type <u32, [u8; BUFFER_SIZE]> (where BUFFER_SIZE is a constant equal to 128k), allowing the insertion of new values and the retrieval of a pointer to a value identified by the u32 key, which can be called from Javascript and is used to write data to the specific buffer as requested by a request RPC.

Building

rustup target add wasm32-unknown-unknown
cargo build --release --target=wasm32-unknown-unknown

Serving

You can run a simple static server with cargo:

cargo install basic-http-server
basic-http-server .

Running the example

# Go to the rust project.
cd rs
# Build the main example.
rustup target add wasm32-unknown-unknown
cargo build --release --example main
# Go back to the root folder.
cd ../
# Serve files statically from root.
cargo install basic-http-server
basic-http-server .
# Open localhost:PORT/examples/main
Commit count: 70

cargo fmt