Skip to main content

Crate trumly_wasm

Crate trumly_wasm 

Source
Expand description

trumly-core for the browser. No wasm-bindgen: three plain functions, so the only tool needed is cargo build --target wasm32-unknown-unknown.

A WASM module can only exchange numbers with JavaScript, so text goes through the module’s memory: JS asks us to alloc a buffer, copies bytes in, calls check, reads the answer bytes back out of memory, then calls dealloc on both buffers.

input (JSON): [[“path.md”, “file text”], …] output (JSON): the check --json document, or {“error”: “…”}

Functions§

alloc
Reserve len bytes inside the module and return where they are.
check_json⚠
Run check over the JSON input at (ptr, len). Returns the output location packed into one u64: high 32 bits = pointer, low 32 bits = length. (wasm32 pointers are 32 bits.)
dealloc⚠
Give a buffer back. len must be the length passed to alloc (or returned by check).
run
The safe part, separated so it can be tested without any pointers.