#[derive_deserialize] for generic tuple structs

This commit is contained in:
Erick Tryzelaar
2015-03-08 11:39:20 -07:00
parent 8bcdd7afe8
commit 9134cff155
2 changed files with 107 additions and 26 deletions
+26 -5
View File
@@ -30,10 +30,6 @@ trait Trait {
#[derive_deserialize]
struct NamedUnit;
#[derive(Debug, PartialEq)]
#[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> {
@@ -87,7 +83,11 @@ fn test_named_unit() {
}
#[test]
fn test_named_tuple() {
fn test_ser_named_tuple() {
#[derive(Debug, PartialEq)]
#[derive_serialize]
struct NamedTuple<'a, 'b, A: 'a, B: 'b, C>(&'a A, &'b mut B, C);
let a = 5;
let mut b = 6;
let c = 7;
@@ -104,6 +104,27 @@ fn test_named_tuple() {
);
}
#[test]
fn test_de_named_tuple() {
#[derive(Debug, PartialEq)]
#[derive_deserialize]
struct NamedTuple<A, B, C>(A, B, C);
assert_eq!(
json::from_str("[1,2,3]").unwrap(),
NamedTuple(1, 2, 3)
);
assert_eq!(
json::from_str("[1,2,3]").unwrap(),
Value::Array(vec![
Value::I64(1),
Value::I64(2),
Value::I64(3),
])
);
}
#[test]
fn test_named_map() {
let a = 5;