Add support for serializing newtype structs

This enables formats like JSON to serialize newtype wrapper
structs without the normal object wrapper. Consider types like:

```rust
struct Point {
    x: u32,
    y: u32,
}

stuct MyPoint(Point);
```

Before this patch, `MyPoint(1,2)` would get serialized as
`[{"x":1,"y":2}]`, but now it gets serialized as `{"x":1,"y"2}`.
This commit is contained in:
Erick Tryzelaar
2015-07-30 09:38:09 -07:00
parent 6715fb6652
commit 97528b59cf
7 changed files with 180 additions and 41 deletions
+9
View File
@@ -453,6 +453,15 @@ impl<Iter> de::Deserializer for Deserializer<Iter>
}
}
#[inline]
fn visit_newtype_struct<V>(&mut self,
_name: &str,
mut visitor: V) -> Result<V::Value, Error>
where V: de::Visitor,
{
visitor.visit_newtype_struct(self)
}
#[inline]
fn visit_enum<V>(&mut self,
_name: &str,