Add type parameters to generated lenses of generic structs.#1591
Add type parameters to generated lenses of generic structs.#1591rjwittams merged 1 commit intolinebender:masterfrom
Conversation
This gives type inference something to grab hold of when chaining LensExt methods or using WidgetExt::lens.
e4961cd to
ae6bdf8
Compare
|
I realised I could use tuple structs to avoid making up idents for PhantomDatas, and I am skipping lifetime parameters for these anyway as I don't think they are needed - so have added and used the const fn new . It would be possible to make the generated structs identical to their current form if they have no args. |
cmyr
left a comment
There was a problem hiding this comment.
It would be possible to make the generated structs identical to their current form if they have no args.
I doubt that anyone is relying on this, and it would make this code a bit more complex (a few more conditionals etc).
Not sure I totally understand, do you mean possible to keep them unit structs?
iirc I have maybe once needed to go find the actual type of a generated lens, but I don't think we should expect anyone to ever use these directly; I think if they need to it's because we've done something wrong.
In any case I think this looks good and definitely improves ergonomics.
|
Yeah the only case it would matter is if someone is referencing the type directly as a value. Which seems unlikely, as we provide the const fields for that purpose. |
…er#1591) This gives type inference something to grab hold of when chaining LensExt methods or using WidgetExt::lens.
This gives type inference something to grab hold of when chaining
LensExt methods or using WidgetExt::lens.
It removes the need for providing annoying and hard to work out type arguments to some method calls (removed one in Tabs).
This changes generated lenses from unit structs to field structs to hold PhantomDatas, so construction is more involved. It also adds generic parameters to these structs, so their types are changed.
A new method wasn't generated and used for the const fields in the targets impl, as lifetime parameters on const functions are unstable.