dtolnay / erased-serde

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

Implement traits `Deserialize` and `DeserializeOwned` in the crate #97

Closed SpriteOvO closed 11 months ago

SpriteOvO commented 11 months ago

The code you wrote in https://github.com/dtolnay/erased-serde/issues/33#issuecomment-605387719 is very generic, why not include it in this crate? So that users no longer copy this code to each of their own crates, and erased-serde can also provide traits that are consistent with serde.

dtolnay commented 11 months ago

It is not built in because that particular trait is never what I have needed in my own uses of deserializing with erased-serde.

SpriteOvO commented 11 months ago

FWIW, this is my use case:

pub struct Registry {
    components: HashMap<String, Box<dyn ErasedDeserializeOwned>>,
}

impl Registry {
    pub fn register(
        &mut self,
        name: impl Into<String>,
        value: impl serde::de::DeserializeOwned,
    ) -> Result<()> {
        self.components.insert(name.into(), Box::new(value));
        Ok(())
    }
}

If I open a PR for adding it into the crate, would you mind merging it?

dtolnay commented 11 months ago

I would not merge it. I think I would need to see evidence of an equivalent trait being broadly used in many crates that use erased-serde's Deserializer.