Skip to content

Commit

Permalink
Merge pull request toby#14 from thequux/master
Browse files Browse the repository at this point in the history
Made newtype struct deserialization work with derived instances
  • Loading branch information
toby authored Feb 23, 2018
2 parents c1e1595 + 7c419ec commit fd95a42
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,12 @@ impl<'de, 'a, R: Read> de::Deserializer<'de> for &'a mut Deserializer<R> {
forward_to_deserialize_any! {
i64 string seq bool i8 i16 i32 u8 u16 u32
u64 f32 f64 char str unit bytes byte_buf map unit_struct tuple_struct tuple
newtype_struct ignored_any identifier struct
ignored_any identifier struct
}

#[inline]
fn deserialize_newtype_struct<V: de::Visitor<'de>>(self, _name: &'static str, visitor: V) -> Result<V::Value> {
visitor.visit_newtype_struct(self)
}

#[inline]
Expand Down
3 changes: 2 additions & 1 deletion tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,11 @@ fn serialize_lexical_sorted_keys() {

#[test]
fn serialize_newtype_struct() {
#[derive(Serialize)]
#[derive(Serialize,Deserialize,Debug,Eq,PartialEq)]
struct Fake(i32);
let f = Fake(66);
assert_eq!(to_string(&f).unwrap(), "i66e");
test_ser_de_eq(f);
}

#[test]
Expand Down

0 comments on commit fd95a42

Please sign in to comment.