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:
asdsad
2020-05-10 04:58:28 +01:00
committed by GitHub
parent 3c97e1b9a9
commit 172edc4cf4
2 changed files with 43 additions and 34 deletions
+14
View File
@@ -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),