Closed Diggsey closed 5 years ago
Thanks so much for doing this. Indeed, this area of the code has been needing some additional love for a while, exactly for the reasons you cited (better readability, extendability)
There are several features that could be added as follow-ups to this PR:
- Addition of
IntoGeneric
trait and implementation ofGeneric
for references to types derivingGeneric
.- Support for deriving
Generic
andLabelledGeneric
on enums.Are these features you would want to add?
Most definitely, those would be amazing to have. If I was a prioritising man, I would say the deriving LabelledGeneric
for enums would probably be on the top of that list :)
Also, sorry for the delayed response; I'm currently on vacation and will take a closer look when I'm back and settled in. Looking awesome thus far !
I've added a rustfmt commit.
This should make it much easier to extend these derives to support enums.
The only change to behaviour should be that
LabelledGeneric
can now be derived on unit structs.Changes to the generated code:
Renamed
'_frunk_labelled_generic_ref_
to_frunk_ref_
because the new code is no longer specific to labelled generics. It would be easy to extend the "ref" implementations to support plainGeneric
if desired.Instead of extracting the
value
fromField
s using property accessor syntax (field.value
) it is destructed directly from the HList, usingField { value: <x>, .. }
. This has the advantage of allowing the construction and destructuring of the user's type to use identical syntax.Changes to naming conventions:
There are three main "places" where generated code is used: types, expressions and patterns. This is complicated by the fact that much syntax is valid as both an expression and a pattern. The convention I used is for
build_xxx_constr
methods to be usable in both expression and pattern locations, whilstbuild_xxx_type
,build_xxx_expr
andbuild_xxx_pat
methods are self explanatory.For normal/ref/mutable ref variations, always use the suffixes/_ref/_mut.
There are several features that could be added as follow-ups to this PR:
IntoGeneric
trait and implementation ofGeneric
for references to types derivingGeneric
.Generic
andLabelledGeneric
on enums.Are these features you would want to add?