lloydmeta / frunk

Funktional generic type-level programming in Rust: HList, Coproduct, Generic, LabelledGeneric, Validated, Monoid and friends.
https://beachape.com/frunk/
MIT License
1.29k stars 58 forks source link

Remove redundant AsRef implementations and &'a-based trait impls. #110

Closed lloydmeta closed 6 years ago

lloydmeta commented 6 years ago

This helps us avoid overflows when implementing our recursive traits (e.g. https://github.com/lloydmeta/frunk/pull/106#issuecomment-377927198).

Instead, introduce a ToRef trait and impls that allows us to turn &'a HCons<H, Tail> into HCons<&'a H, <&'a Tail as ToRef>::Output>.

Unlike AsRef, we are not restricted to having to return a &T.

See https://github.com/lloydmeta/frunk/pull/106#issuecomment-377957019

Note I couldn't really make this work with the Hlist! type macro I needed to use the associated Output type from the tail implementation.