-
Notifications
You must be signed in to change notification settings - Fork 26
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
CLVM derive support for enums #325
Conversation
Pull Request Test Coverage Report for Build 7071376448Warning: This coverage report may be inaccurate.We've detected an issue with your CI configuration that might affect the accuracy of this pull request's coverage report.
💛 - Coveralls |
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 all the way through this review yet. But here's what I've got so far.
Generally I think it would be good with more comments explaining what's going on. Macro code is especially unintuitive sometimes.
I appreciate the refactoring of fields()
and repr_macros()
to handle the different kinds of types in a uniform way (although I think they could both use comments describing what they do).
As for the named "untagged", maybe it would make sense to give it a name that describes the behavior instead. i.e. that it will perform a match instead. I don't know, untagged isn't so bad either (as along as it's well documented).
The exact behavior would ideally also be demonstrated in a test. regarding match-first, match-best or ambiguity being an error.
This PR adds support for deriving
ToClvm
andFromClvm
on enums:isize
and starts at0
incrementing by1
per variant unless overridden, similar to the defaults used byrustc
.#[repr(u16)]
).tuple
layout.list
andtuple
enums, you can useuntagged
to indicate that each of the variants are to be parsed individually and with no discriminator. This is useful for matching one of a set of possible values.You can also derive these traits on unit structs, although this just encodes the value as if it had no fields and isn't too useful.
The quality of the code was also improved, and some of the duplicated logic was refactored out of each individual macro into the helpers file.
This should have no noticeable breaking changes in the way other derives work as far as I know.