wa-lang.org/wazero@v1.0.2/examples/allocation/rust/README.md (about) 1 ## Rust allocation example 2 3 This example shows how to pass strings in and out of a Wasm function defined 4 in Rust, built with `cargo build --release --target wasm32-unknown-unknown` 5 6 ```bash 7 $ go run greet.go wazero 8 Hello, wazero! 9 ``` 10 11 Under the covers, [lib.rs](testdata/src/lib.rs) does a few things of interest: 12 * Uses a WebAssembly-tuned memory allocator: [wee_alloc](https://github.com/rustwasm/wee_alloc). 13 * Exports wrapper functions to allocate and deallocate memory. 14 * Uses `&str` instead of CString (NUL-terminated strings). 15 * Uses `std::mem::forget` to prevent Rust from eagerly freeing pointers returned. 16 17 Note: We chose to not use CString because it keeps the example similar to how 18 you would track memory for arbitrary blobs. We also watched function signatures 19 carefully as Rust compiles different WebAssembly signatures depending on the 20 input type. 21 22 See https://wazero.io/languages/rust/ for more tips.