Skip to content

Commit

Permalink
Merge pull request #1669 from H2CO3/master
Browse files Browse the repository at this point in the history
Allow untagged unit variants to deserialize from `Visitor::visit_none()`
  • Loading branch information
dtolnay committed Nov 25, 2019
2 parents 533fb9c + 97a98a7 commit ff70409
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 7 additions & 0 deletions serde/src/private/de.rs
Expand Up @@ -2510,6 +2510,13 @@ mod content {
{
Ok(())
}

fn visit_none<E>(self) -> Result<(), E>
where
E: de::Error,
{
Ok(())
}
}
}

Expand Down
8 changes: 3 additions & 5 deletions test_suite/tests/test_macros.rs
Expand Up @@ -637,7 +637,10 @@ fn test_untagged_enum() {
],
);

// Serializes to unit, deserializes from either depending on format's
// preference.
assert_tokens(&Untagged::C, &[Token::Unit]);
assert_de_tokens(&Untagged::C, &[Token::None]);

assert_tokens(&Untagged::D(4), &[Token::U8(4)]);
assert_tokens(&Untagged::E("e".to_owned()), &[Token::Str("e")]);
Expand All @@ -652,11 +655,6 @@ fn test_untagged_enum() {
],
);

assert_de_tokens_error::<Untagged>(
&[Token::None],
"data did not match any variant of untagged enum Untagged",
);

assert_de_tokens_error::<Untagged>(
&[Token::Tuple { len: 1 }, Token::U8(1), Token::TupleEnd],
"data did not match any variant of untagged enum Untagged",
Expand Down

0 comments on commit ff70409

Please sign in to comment.