Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Untagged unit variant fails to deserialize from visit_none() #1668

Closed
H2CO3 opened this issue Nov 6, 2019 · 0 comments · Fixed by #1669
Closed

Untagged unit variant fails to deserialize from visit_none() #1668

H2CO3 opened this issue Nov 6, 2019 · 0 comments · Fixed by #1669

Comments

@H2CO3
Copy link
Contributor

H2CO3 commented Nov 6, 2019

I'm writing a serialization format that uses explicit optionals. Similarly to serde_json::Value, my Value enum has a Null variant representing the null value. When asked to deserialize_any(), this null value calls visit_none() on the supplied visitor. However, UntaggedUnitVisitor doesn't implement visit_none(), only visit_unit(), so this fails.

It seems to me that UntaggedUnitVisitor should ideally implement visit_none() because OptionVisitor treats unit and None as the same, so this would be the consistent behavior.

Another reason is that although I could fix the error by making Value::deserialize_any() call visitor.visit_unit() instead of visitor.visit_none(), I'd rather not change this behavior, because untagged enums are what I would consider more of a less-used special case, whereas Option has very regular structure and semantics, and it is used a lot more frequently too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant