Re:Deriving Traits in Rust with Procedural Macros
by bpicolo on Wednesday January 02, 2019 @10:13PM
(#18812532)
Procedural macros are something you more or less never need to write in application code, but they add tremendous power to libraries
[ Parent
| on HN ]
Re:Deriving Traits in Rust with Procedural Macros
by lmm on Thursday January 03, 2019 @05:37AM
(#18814180)
Deriving typeclass implementations is something I do all the time in regular application code (in Scala), once you're used to it it gives you a lot of safety and expressive power. It sounds like Rust would benefit from some kind of record system / generic representation of traits (like we get from Shapeless in Scala) so that generic trait deriving could be written in normal code without needing macros.
Re:Deriving Traits in Rust with Procedural Macros
by papaf on Thursday January 03, 2019 @06:07AM
(#18814286)
Isn't Shapeless based in macros?
That said, an equivalent library in Rust would be very useful.
Re:Deriving Traits in Rust with Procedural Macros
by lmm on Thursday January 03, 2019 @06:11AM
(#18814304)
Shapeless has one or two macros in its implementation, but as far as the rest of the ecosystem is concerned it might as well be part of the language. The point is that you can implement a custom typeclass and derivation of instances of that typeclass for struct-like ((possibly recursive) compositions of) sum/product types without ever having to write a custom macro.
Re:Deriving Traits in Rust with Procedural Macros
by shmerl on Thursday January 03, 2019 @02:00AM
(#18813413)
Which doesn't make it easier, since you might want to structure part of you application code as a reusable library.