/stream of thought mode on
As I’m trying to migrate savaged.us to WebAssembly components using Rust, I’m having to work-around any public fields when returning a Rust struct to my Typescript workflow. The biggest problem I’m having is that String struct variables which are made public don’t support the Copy function.
I can get around this by accessing the fields from wasm_bindgen getters and setters. however, when exporting a data object, there’s no way to get a list of the fields exported for importing the data object later. My frustrating solution is to pass a JSON string and then parse it internally.
Here’s the code after I add a pub note to a struct field:
Here’s the error which occurs:
The same happens to any Vector field with a String param in the Vector object .
Theoretically, I could implement Copy on string variable types myself (likely using .to_string or .as_ref), but this should be handled internally by wasm_bindgen in my inexperienced opinion using this platform.
The current file I’m experimeting with is On my github account, but I’ve not pushed up any breaking changes as I think there’s a few folks who are following along the development there at home.
With the exception of this, so far the conversion of the data and logic to Rust has been pretty smooth despite the slight learning curve. Once I figure out how to get past this, I think I’ll be ready to work on trying to import some .wasm functions at Savaged.us as that .wasm module is only 362K (which may seem big, but it’s not bad considering all the other structs and functions exposed and already written).