mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-30 03:57:55 +00:00
Fix #[derive_deserialize] for generic structs
This commit is contained in:
@@ -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!(
|
||||
|
||||
Reference in New Issue
Block a user