json icon indicating copy to clipboard operation
json copied to clipboard

Deserilazing `Cow<'_, serde_json::value::RawValue>` always allocates

Open monoid opened this issue 2 years ago • 0 comments

It seems the following test should work, but it fails:

#[test]
fn test_cow_raw_value() {
    #[derive(Debug, Serialize, Deserialize)]
    struct V<'a> {
        #[serde(borrow)]
        key: Cow<'a, serde_json::value::RawValue>,
    }

    let a = r#"{"key":[1,2,3]}"#;
    let b: V<'_> = serde_json::from_str(a).expect("valid JSON");

    assert!(matches!(b.key, Cow::Borrowed(_)));
}

monoid avatar Oct 09 '23 17:10 monoid