Closed Diggsey closed 5 years ago
(Rebased and reformatted)
Sorry for the delay in reviewing this a bunch of life things came up and I'm only currently catching up with work and other things. Just took an overall look at this PR, and it looks really good ! Will try to find some time over the weekend to give it a detailed review.
Yeah, for my own use case, the names of the variants are essential, as I'm using frunk to implement conversions between "similar" but separate data structures, and it allows me to generically convert from one enum to another.
The reason I did this was for two reasons:
Generic
instead of LabelledGeneric
Field
/Variant
type easily enough.However, if you think it would be worth adding all four combinations:
Then that would also work.
My eventual goal is to implement something like "transmogrify" in that it uses the field names, but that can be "driven" by the return type. So instead of saying "map X to whatever F(X) happened to return", you could say "convert X to Y" and it would recursively:
I got very close, (got it working at the struct level) but haven't been able to quite get the inference working for coproducts yet 😢
Awesome stuff ! Thanks for the contribution @Diggsey!
(Based off #157)
I reused the
Field
type to represent named enum variants.This is just the first step - to make enums actually useful we'll need to:
Another issue I found is the
field!
macro - the way it generates the field name is inconsistent due to limitations of the macro system (eg.field!((_, _0), ...)
has the name__0
when it should be_0
). It should be possible to implement it as a procedural macro, so that one can just writefield!("_0", ...)
and not have to worry about the encoding.