Crates.io | rwasm |
lib.rs | rwasm |
version | 0.0.1 |
source | src |
created_at | 2020-12-19 15:43:29.784172 |
updated_at | 2022-08-29 12:27:22.614279 |
description | Minimalistic WASM library |
homepage | https://github.com/rellfy/rwasm |
repository | https://github.com/rellfy/rwasm |
max_upload_size | |
id | 324584 |
size | 20,651 |
A minimalistic WASM library for Rust.
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.
The send
RPC type sends data to Javascript and does not expect to receive anything back.
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.
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.
rustup target add wasm32-unknown-unknown
cargo build --release --target=wasm32-unknown-unknown
You can run a simple static server with cargo:
cargo install basic-http-server
basic-http-server .
# 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