-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add JsValue::{from_serde, into_serde} #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
These functions are activated with the `serde-serialization` feature of the `wasm-bindgen` crate. When activated they will allow passing any arbitrary value into JS that implements the `Serialize` trait and receiving any value from JS using the `Deserialize` trait. The interchange between JS and Rust is JSON. Closes #96
Oh. This looks really good. So we serialize incoming objects and pass the string in, vice-versa for passing them out? I think this effectively minimises the number of context switches and is the most pragmatic solution right now. A potential future improvement could be to encode objects in a way which has a more efficient representation and supports skipping properties when decoding. But it will be hard to compete with the efficiency of the built-in JSON support. |
@udoprog precisely! You basically got all the intentions there :) |
Can someone provide an example of how to enable this?
in Cargo.toml, and
both lead to this:
|
@David-OConnor oh so after you enable the features in |
The feature flag is actually @alexcrichton made a typo in the OP here 😛 |
Oops, thanks @jsheard! |
Thank you for the help. I think I'm just not understanding the syntax of how to enable the feature; I've attempted the above two with the correct spelling, plus two additional attempts:
in Cargo.toml: invalid TOML error. |
@David-OConnor oh the trailing comma there is invalid syntax, but if you remove that you should be good! |
Thank you! That worked. |
These functions are activated with the
serde-serialization
serde-serialize
feature of thewasm-bindgen
crate. When activated they will allow passing any arbitrary valueinto JS that implements the
Serialize
trait and receiving any value from JSusing the
Deserialize
trait. The interchange between JS and Rust is JSON.Closes #96