Skip to content

Commit

Permalink
Merge pull request #1045 from ZetaNumbers/value-ref-into-deserializer
Browse files Browse the repository at this point in the history
Implement IntoDeserializer for &Value
  • Loading branch information
dtolnay authored Jul 26, 2023
2 parents 8f90eac + 8e8db8c commit f6cc4f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/value/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,14 @@ impl<'de> IntoDeserializer<'de, Error> for Value {
}
}

impl<'de> IntoDeserializer<'de, Error> for &'de Value {
type Deserializer = Self;

fn into_deserializer(self) -> Self::Deserializer {
self
}
}

struct VariantDeserializer {
value: Option<Value>,
}
Expand Down
6 changes: 6 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2472,6 +2472,12 @@ fn test_value_into_deserializer() {
let mut map = BTreeMap::new();
map.insert("inner", json!({ "string": "Hello World" }));

let outer = Outer::deserialize(serde::de::value::MapDeserializer::new(
map.iter().map(|(k, v)| (*k, v)),
))
.unwrap();
assert_eq!(outer.inner.string, "Hello World");

let outer = Outer::deserialize(map.into_deserializer()).unwrap();
assert_eq!(outer.inner.string, "Hello World");
}
Expand Down

0 comments on commit f6cc4f3

Please sign in to comment.