Open anweiss opened 4 years ago
@anweiss Could you share the definition of your MyType
?
For additional context, I'd ultimately like to avoid having to derive Serialize
and Deserialize
and just append #[wasm_bindgen]
to my types so I can get proper type declarations and avoid unnecessary serialization/deserialization. However, since structs with #[wasm_bindgen]
cannot have lifetime nor type parameters, I'm faced with either deriving Serialize
and Deserialize
or duplicating a ton of code with owned fields in order to support wasm.
Describe the Bug
According to the docs, a
JsValue
can be deserialized into all types that implement theserde::de::Deserialize<'a>
trait. I take this to mean that I should be able to deserialize aJsValue
into types with borrowed fields. However, when attempting to do so, I get an error.Steps to Reproduce
MyType
includes borrowed fields, opted in via#[serde(borrow)]
.However, if I use
serde_json
directly, it seems to work:Expected Behavior
I expected a
JsValue
to be deserializable into a type with borrowed fields using theinto_json()
method.Actual Behavior
I am unable to deserialize a
JsValue
into a type with borrowed fields using theinto_json()
method.