Skip to content

Implement IntoDeserializer for Value and &Value #423

@dtolnay

Description

@dtolnay

An IntoDeserializer impl would provide a way to deserialize from these types while constructing exactly the right error type on failure, rather than constructing a serde_json::Error and mapping it to a custom error of the target type through its Display impl.

fn f<'de, T, D>(deserializer: D) -> Result<T, D::Error>
where
    T: Deserialize<'de>,
    D: Deserializer<'de>,
{
    let mut v = Value::deserialize(deserializer)?;

    /* some manipulation of v */

    T::deserialize(v).map_err(serde::de::Error::custom)
}
- T::deserialize(v).map_err(serde::de::Error::custom)
+ T::deserialize(v.into_deserializer())

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions