Skip to content

Error when deserializing Value to T #165

@rieval

Description

@rieval

Hello! I'm trying to write a helper function that deserializes Value to T and returns a default value if deserialization fails. I noticed that if I replace sonic_rs with serde_json, it's works.

Here is a example code:

pub fn deserialize_skip_error<'de, T, D>(deserializer: D) -> Result<T, D::Error>
where
    T: serde::Deserialize<'de> + Default,
    D: serde::Deserializer<'de>,
{
    let value = sonic_rs::Value::deserialize(deserializer)?;
    let inner = T::deserialize(value).unwrap_or_default();
    Ok(inner)
}

And error logs here:

the trait bound `sonic_rs::Value: extract_id::_::_serde::Deserializer<'_>` is not satisfied
the trait `extract_id::_::_serde::Deserializer<'_>` is not implemented for `sonic_rs::Value`
but it is implemented for `&sonic_rs::Value` for that trait implementation, expected `&sonic_rs::Value`, found `sonic_rs::Value`

Windows 11
rustc 1.86.0-nightly (bef3c3b01 2025-02-04)

crates version:
sonic_rs: main branch
serde: 1.0.216

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions