One more case of handling newtype structs
This commit is contained in:
parent
7a8c535c5a
commit
66bbdb36a6
12
src/de.rs
12
src/de.rs
|
@ -438,9 +438,19 @@ impl<'de, 'b> de::Deserializer<'de> for MapVisitor<'de, 'b> {
|
|||
visitor.visit_some(self)
|
||||
}
|
||||
|
||||
fn deserialize_newtype_struct<V>(
|
||||
self,
|
||||
_name: &'static str,
|
||||
visitor: V
|
||||
) -> Result<V::Value, Error>
|
||||
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 struct unit newtype_struct identifier
|
||||
bytes byte_buf map struct unit identifier
|
||||
ignored_any unit_struct tuple_struct tuple enum
|
||||
}
|
||||
}
|
||||
|
|
|
@ -525,3 +525,32 @@ fn newtypes() {
|
|||
Table(map! { b: Integer(2) }),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn newtypes2() {
|
||||
#[derive(Deserialize, Serialize, PartialEq, Debug, Clone)]
|
||||
struct A {
|
||||
b: B
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, PartialEq, Debug, Clone)]
|
||||
struct B(Option<C>);
|
||||
|
||||
#[derive(Deserialize, Serialize, PartialEq, Debug, Clone)]
|
||||
struct C {
|
||||
x: u32,
|
||||
y: u32,
|
||||
z: u32
|
||||
}
|
||||
|
||||
equivalent! {
|
||||
A { b: B(Some(C { x: 0, y: 1, z: 2 })) },
|
||||
Table(map! {
|
||||
b: Table(map! {
|
||||
x: Integer(0),
|
||||
y: Integer(1),
|
||||
z: Integer(2)
|
||||
})
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue