Skip to content

Allow Serialize/Deserialize into a JsValue #96

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

Closed
alexcrichton opened this issue Mar 29, 2018 · 3 comments
Closed

Allow Serialize/Deserialize into a JsValue #96

alexcrichton opened this issue Mar 29, 2018 · 3 comments
Labels
help wanted We could use some help fixing this issue!

Comments

@alexcrichton
Copy link
Contributor

We should have an option to convert an arbitrary object to a JsValue via Serialize an Deserialize. It may not be quick but it's often quite useful!

@udoprog
Copy link

udoprog commented Mar 29, 2018

I want to take a stab at this and have a couple of questions.

Would you be in favor changing JsValue into an enum to make it easier to match based on its type during serialization?

It's not apparent how we deal with objects and arrays right now (if at all). Would you mind providing some instructions for how that would work?

@alexcrichton
Copy link
Contributor Author

Nah for now I'd like to leave JsValue opaque as it represents a foreign JS object which we don't know the value of. I think it'd be fine though to add a decode method which could return an enum, however, storing the various values internally.

I think that implementing this may actually be easiest to just convert straight to JSON, send that to JS, and then parse the object and return an index. Alternatively we could add accessors/creators to JsValue for objects and arrays (e.g. the ability to set keys), but that would involve crossing the wasm/JS boundary which may not be as efficient

@alexcrichton alexcrichton added closures Adding more support for closures on the boundary help wanted We could use some help fixing this issue! and removed closures Adding more support for closures on the boundary labels Apr 5, 2018
alexcrichton added a commit that referenced this issue Apr 27, 2018
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
alexcrichton added a commit that referenced this issue Apr 27, 2018
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
@alexcrichton
Copy link
Contributor Author

I've posted an initial pass of this API at #171

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted We could use some help fixing this issue!
Projects
None yet
Development

No branches or pull requests

2 participants