dtolnay / erased-serde

Type-erased Serialize, Serializer and Deserializer traits
Apache License 2.0
709 stars 36 forks source link

Why is there no Deserialize trait and macro? #46

Closed nyovaya closed 2 years ago

nyovaya commented 2 years ago

This will fail for me, do I need to manually implement something or is there something missing yet?

`#[derive(Serialize, Deserialize)] struct Foo{ bar: A }

[derive(Serialize, Deserialize)]

struct A(HashMap<String, Box>);

[derive(Serialize, Deserialize)]

struct B{ field: u32 }

pub trait Bar: erased_serde::Serialize + Any{

}

erased_serde::serialize_trait_object!(Bar);

impl Bar for B{

}`

dtolnay commented 2 years ago

Please see #25.

The Deserialize trait's associated function does not take a self, so there is no thing to box or turn into a trait object prior to the deserialization being performed. And after something has been deserialized, turning it into a dyn deserialize is useless because all the deserializing has already been completed.

nyovaya commented 2 years ago

@dtolnay Do you have an example for deserialization, like within a struct?