arcnmx / serde-value

Serialization value trees
http://arcnmx.github.io/serde-value/serde_value/
MIT License
43 stars 30 forks source link

Provide separate ValueDeserializer that's generic on the Error type #23

Closed Arnavion closed 5 years ago

Arnavion commented 5 years ago

The serde::private::de::Content does not impl Deserializer itself, rather a separate ContentDeserializer type implements it. This allows ContentDeserializer to be used inside Deserialize impls, since Deserialize impls must be generic on the Error type.

The same cannot be done with serde_value::Value since it impls Deserializer on itself with a fixed Error = serde_value::DeserializerError type.

It would be useful to have a separate

struct ValueDeserializer<E: serde::de::Error>(Value, PhantomData<E>);

impl<'de, E: serde::de::Error> Deserialize<'de> for ValueDeserializer<E> {
    type Error = E;

    // same as current Value impl, except for visit_seq and visit_map
    // that need to wrap the value in Self first
}

Content's Deserializer impl could then forward to ContentDeserializer<serde_value::DeserializerError> to maintain backward compatibility.