Fix #[derive_deserialize] for generic structs

This commit is contained in:
Erick Tryzelaar
2015-03-08 18:46:41 -07:00
parent cdb3ed30ab
commit 419f34c665
2 changed files with 91 additions and 17 deletions
+40 -9
View File
@@ -30,14 +30,6 @@ trait Trait {
#[derive_deserialize]
struct NamedUnit;
#[derive(Debug, PartialEq)]
#[derive_serialize]
struct NamedMap<'a, 'b, A: 'a, B: 'b, C> {
a: &'a A,
b: &'b mut B,
c: C,
}
#[derive(Debug, PartialEq)]
#[derive_serialize]
//#[derive_deserialize]
@@ -126,7 +118,15 @@ fn test_de_named_tuple() {
}
#[test]
fn test_named_map() {
fn test_ser_named_map() {
#[derive(Debug, PartialEq)]
#[derive_serialize]
struct NamedMap<'a, 'b, A: 'a, B: 'b, C> {
a: &'a A,
b: &'b mut B,
c: C,
}
let a = 5;
let mut b = 6;
let c = 7;
@@ -151,6 +151,37 @@ fn test_named_map() {
);
}
#[test]
fn test_de_named_map() {
#[derive(Debug, PartialEq)]
#[derive_deserialize]
struct NamedMap<A, B, C> {
a: A,
b: B,
c: C,
}
let v = NamedMap {
a: 5,
b: 6,
c: 7,
};
assert_eq!(
json::from_str("{\"a\":5,\"b\":6,\"c\":7}").unwrap(),
v
);
assert_eq!(
json::from_value(Value::Object(btreemap![
"a".to_string() => Value::I64(5),
"b".to_string() => Value::I64(6),
"c".to_string() => Value::I64(7)
])).unwrap(),
v
);
}
#[test]
fn test_enum_unit() {
assert_eq!(