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