-
Notifications
You must be signed in to change notification settings - Fork 127
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
Adds unwrap_variant_newtypes extension #319
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite sure yet if we should use the implemented behavious (forbidding parantheses unless the struct name is given) - I'm not sure if this might be confusing.
Regarding breaking changes, on a first glance it doesn't look like a breaking change but I need to read through it again. I wouldn't worry about bumping version though, because RON barely ever gets exposed so upgrading really isn't an issue.
My reasoning was to make sure that the parsing is unambiguous. If parentheses were still accepted but optional, we wouldn’t know if they are part of the wrapped struct or its inner content … though maybe this could be solved by eagerly eating them but remembering that we were eager. If we then check for parentheses but can’t find any and this flag is set, we could infer that the parentheses were part of the inner type (and then apply that knowledge when parsing the outer parenthesis). However, this logic might be a bit complicated … |
Thanks for the explanation! @MomoLangenstein |
@torkleyy So forbidding |
Yes, exactly @MomoLangenstein, that's what I was thinking. If you can do that, I'd be willing to merge this - except @kvark has any concerns? |
That seems fine, and useful. I appreciate the strictness proposed. Let's not forget to adjust the PR description accordingly. |
Brilliant, I'll change up the PR then |
@torkleyy I have implemented the changes and updated & extended the tests. I've also added a quick extension description inside the docs folder - I hope this has the right format? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lovely PR, with tests & docs, thank you @MomoLangenstein
bors r+
Configuration problem: |
Thanks @torkleyy for your help and guidance! |
This PR fixes #250 by adding a new
unwrap_variant_newtypes
extension. When enabled, newtype variants will skip the outer parentheses of the wrapped type:In this example,
Foo
can now be parsed fromA(b: 4)
.Notes
unwrap_variant_newtypes
, neitherA(A(b: 4))
norA((b: 4))
will parse, as unwrapping newtype variants is always performed.unwrap_newtypes
if the newtype variant wraps around a newtype struct. Both extensions are compatible, but in this caseunwrap_newtypes
is not needed as the newtype variant can also perform the unwrapping.