I'm building a function in Rust that processes binary files: It accepts file contents as input, and returns totally new file contents.
I want to expose my Rust function in Javascript. It accepts a Uint8Array as an argument. I got that working very quickly.
However, I'm stumped how to return an Uint8Array.
While investigating, I tried copying the code from Boxed Number Slices - The `wasm-bindgen` Guide
#[wasm_bindgen]
pub fn return_boxed_number_slice() -> Box<[u32]> {
(0..42).collect::<Vec<u32>>().into_boxed_slice()
}
However, when I try to compile the code with wasm-pack, I see this error:
% wasm-pack build | more
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
Compiling freesplit v0.1.0 (/Users/jeff/gitrepos/code/code/freesplit)
Finished release [optimized] target(s) in 0.21s
[INFO]: Installing wasm-bindgen...
[INFO]: Optimizing wasm binaries with `wasm-opt`...
[wasm-validator error in module] unexpected true: Exported global cannot be mutable, on
global$0
My code doesn't export any globals, so I'm stumped.
Thanks for helping!