mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-22 19:28:01 +00:00
Allow optional content field for adjacently tagged newtype variants
* Deserialize adjacently tagged newtype variants with optional content as None instead of erroring when content field is missing * refactor to remove duplicate code and remove panic
This commit is contained in:
@@ -1145,6 +1145,20 @@ fn test_adjacently_tagged_enum() {
|
||||
],
|
||||
);
|
||||
|
||||
// optional newtype with no content field
|
||||
assert_de_tokens(
|
||||
&AdjacentlyTagged::Newtype::<Option<u8>>(None),
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("t"),
|
||||
Token::Str("Newtype"),
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
// tuple with tag first
|
||||
assert_tokens(
|
||||
&AdjacentlyTagged::Tuple::<u8>(1, 1),
|
||||
|
||||
Reference in New Issue
Block a user