I still struggle (as someone learning Rust) with being able to add WASM support to general purpose Rust crates. I compiled rs-natural with wasm-pack but realized it was unusable because I couldn't access any of the functions from js.
Besides the tips in this article, is there anything else to look out for when trying to use a general crate to target wasm?
in the same way as if you were trying to use a random crate from C you would need to wrap the crate and provide a C API, you will need to do the same thing for providing Wasm exports that make the crate's functionality available to JS
typically, this involves writing a new crate that depends on your target crate and wasm-bindgen, and uses wasm-bindgen to define an interface for working with the underlying crate
Last updated: Dec 23 2024 at 12:05 UTC