Fix #[derive_serialize] for generic structs

This commit is contained in:
Erick Tryzelaar
2015-03-06 22:14:13 -08:00
parent a565df9cf7
commit 124a306cd7
2 changed files with 65 additions and 20 deletions
+34
View File
@@ -33,6 +33,14 @@ struct NamedUnit;
#[derive_serialize]
struct NamedTuple<'a, 'b, A: 'a, B: 'b, C>(&'a A, &'b mut B, C);
#[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]
@@ -97,6 +105,32 @@ fn test_named_tuple() {
);
}
#[test]
fn test_named_map() {
let a = 5;
let mut b = 6;
let c = 7;
let named_map = NamedMap {
a: &a,
b: &mut b,
c: c,
};
assert_eq!(
json::to_string(&named_map).unwrap(),
"{\"a\":5,\"b\":6,\"c\":7}"
);
assert_eq!(
json::to_value(&named_map),
Value::Object(btreemap![
"a".to_string() => Value::I64(5),
"b".to_string() => Value::I64(6),
"c".to_string() => Value::I64(7)
])
);
}
#[test]
fn test_enum_unit() {
assert_eq!(