mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-22 22:58:02 +00:00
Allow structs to be deserialized from sequences
This relies on the sequence to have the same ordering as the struct field order.
This commit is contained in:
@@ -891,7 +891,7 @@ fn test_parse_struct() {
|
||||
Inner { a: (), b: 2, c: vec!["abc".to_string(), "xyz".to_string()] }
|
||||
]
|
||||
},
|
||||
)
|
||||
),
|
||||
]);
|
||||
|
||||
let v: Outer = from_str("{}").unwrap();
|
||||
@@ -902,6 +902,22 @@ fn test_parse_struct() {
|
||||
inner: vec![],
|
||||
}
|
||||
);
|
||||
|
||||
let v: Outer = from_str(
|
||||
"[
|
||||
[
|
||||
[ null, 2, [\"abc\", \"xyz\"] ]
|
||||
]
|
||||
]").unwrap();
|
||||
|
||||
assert_eq!(
|
||||
v,
|
||||
Outer {
|
||||
inner: vec![
|
||||
Inner { a: (), b: 2, c: vec!["abc".to_string(), "xyz".to_string()] }
|
||||
],
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -934,7 +950,7 @@ fn test_parse_enum_errors() {
|
||||
("{\"unknown\":[]}", Error::SyntaxError(ErrorCode::UnknownField("unknown".to_string()), 1, 11)),
|
||||
("{\"Dog\":{}}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 9)),
|
||||
("{\"Frog\":{}}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 10)),
|
||||
("{\"Cat\":[]}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 9)),
|
||||
("{\"Cat\":[]}", Error::SyntaxError(ErrorCode::EOFWhileParsingValue, 1, 9)),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user