4 ms·
Procedural macros are something you more or less never need to write in application code, but they add tremendous power to libraries
by bpicolo 8y ago
Procedural macros are something you more or less never need to write in application code, but they add tremendous power to libraries
- shmerl 8y agoWhich doesn't make it easier, since you might want to structure part of you application code as a reusable library.
- atoav 8y agoIt is entirely optional. I use Rust for two years now and work on a few things (biggest one around 10kLOC). I didn’t even read the Macro section in my books yet. Because I didn’t need to.
- keldaris 8y agoMost of the complexity of C++ is entirely optional too. That doesn't make the observation any less valid.
- lmm 8y agoDeriving 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.
- papaf 8y agoIsn't Shapeless based in macros? That said, an equivalent library in Rust would be very useful.
- lmm 8y agoShapeless 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.