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

derive support for enums with newtype/unit variants #233

Merged
merged 39 commits into from
Sep 25, 2024
Merged

derive support for enums with newtype/unit variants #233

merged 39 commits into from
Sep 25, 2024

Conversation

jordens
Copy link
Member

@jordens jordens commented Sep 23, 2024

  • Only newtype and unit variants supported currently. Non-newtype tuple structs can be used with skip fields. Both record structs and non-newtype tuple structs would require creating proxy structs on the fly to implement KeyLookup and TreeKey on them.
  • The .0 newtype hierarchy level is flattened intrinsically.
  • Unit variants are supported by being equivalent to skip. They would only become relevant once there is some instrinsic support for switching variants.
  • No intrinsic support for variant read. An external getter can be used.
  • No intrinsic support for variant write. An external setter can be used. This needs some user code in any case since there is no Default per variant.
  • The implementation differs from the one proposed in derive macro for complex enums #166 in that even for depth = 1, there is no intrinsic support for variant switching.
  • No support for variant flattening. This is the only thing that would be missing to support Option-style behavior through the derive macros.

@jordens jordens linked an issue Sep 23, 2024 that may be closed by this pull request
@jordens jordens changed the title enum newtype/unit enum support Sep 23, 2024
@jordens jordens changed the title newtype/unit enum support derive newtype/unit enum support Sep 23, 2024
@jordens
Copy link
Member Author

jordens commented Sep 24, 2024

@MathiasKoch does this help you? There are some examples in tests/enum.rs.

@jordens jordens changed the title derive newtype/unit enum support derive support for enums with newtypes/unit variants Sep 24, 2024
@MathiasKoch
Copy link

This looks amazing!
I never got around to implementing it myself yet, but this will absolutely help!

@jordens jordens changed the title derive support for enums with newtypes/unit variants derive support for enums with newtype/unit variants Sep 24, 2024
@jordens jordens linked an issue Sep 25, 2024 that may be closed by this pull request
@jordens jordens merged commit 6a93011 into main Sep 25, 2024
7 checks passed
@jordens jordens deleted the enum branch September 25, 2024 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

py: dump (list-and-get ?) on leaf nodes hangs derive macro for complex enums
2 participants