From ad5bd8758e60fc918423bbbf3dedf04037487d62 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 6 Jul 2017 07:34:45 -0700 Subject: Support deserializing newtypes Closes #196 --- src/de.rs | 13 +++++++++++-- src/value.rs | 12 +++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/de.rs b/src/de.rs index d5af272..77b5ee5 100644 --- a/src/de.rs +++ b/src/de.rs @@ -248,7 +248,6 @@ impl<'de, 'b> de::Deserializer<'de> for &'b mut Deserializer<'de> { } } - forward_to_deserialize_any! { bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string seq bytes byte_buf map struct unit newtype_struct @@ -560,9 +559,19 @@ impl<'de> de::Deserializer<'de> for ValueDeserializer<'de> { } } + fn deserialize_newtype_struct( + self, + _name: &'static str, + visitor: V + ) -> Result + where V: de::Visitor<'de> + { + visitor.visit_newtype_struct(self) + } + forward_to_deserialize_any! { bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string seq - bytes byte_buf map unit newtype_struct identifier + bytes byte_buf map unit identifier ignored_any unit_struct tuple_struct tuple } } diff --git a/src/value.rs b/src/value.rs index 5efdb92..056eac4 100644 --- a/src/value.rs +++ b/src/value.rs @@ -544,10 +544,20 @@ impl<'de> de::Deserializer<'de> for Value { visitor.visit_some(self) } + fn deserialize_newtype_struct( + self, + _name: &'static str, + visitor: V + ) -> Result + where V: de::Visitor<'de> + { + visitor.visit_newtype_struct(self) + } + forward_to_deserialize_any! { bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit seq bytes byte_buf map unit_struct tuple_struct struct - tuple ignored_any newtype_struct identifier + tuple ignored_any identifier } } -- cgit v1.2.3