I've got some core functionality, primarily an algorithm that i'm trying to reuse in web assembly and java.
I'm using wasm-bindgen and serde, I notice that wasm-bindgen and serde is tightly coupled to my algorithm via the use of attributes. i.e; #[wasm_bindgen]
and #[derive(Serialize, Deserialize)]
-- i'm quite new to rust so i'm wondering how I can decouple these attributes from my function and struct so that I can reuse my functions and structs in my implementation that will interface with java. At the moment because they're tightly coupled if I was to try and use these functions on a platform that isn't wasm it'll throw a panic.
Serialize
and Deserialize
are not specific to wasm and are available on other platforms.
For wasm_bindgen
, you can use the cfg_attr
attribute to only define it for the wasm
platform if you replace #[wasm_bindgen
with #[cfg_attr (wasm, wasm_bindgen)]
.