As someone who has spent a _lot_ of time writing declarative and procedural macros, the important thing to ask before digging into a macro is whether you need a procedural macro at all.
Complex proc macros absolutely do slow builds down. In many cases, a proc macro only need to be a stub that can delegate to a declarative macro.
You may not need to use syn/quote, but if you are doing any sort of processing/parsing of Rust code you pretty much need to.
FWIW, I really hope that the Rust project focused on finer-grained token matching in declarative macros so we can migrate most proc_macro code away. The macro system is powerful, but nowhere near where it needs to be.
It's interesting seeing this discussion in Rust because it's the same discussion that's been happening around macros in Scheme for decades. It's one of those things or there probably is no universal correct answer, so might as well allow both in your language and let the programmer decide what's best for their case.
Couldn't agree more, both on proc macros and operating system, I did not find sufficient information on the internet. That is exactly the purpose of this book.
> FWIW, I really hope that the Rust project focused on finer-grained token matching in declarative macros so we can migrate most proc_macro code away. The macro system is powerful, but nowhere near where it needs to be.
I'm sick of how slow it is.
There has to be a more appropriate DSL for something like Serde that doesn't make big API surface area apps take ten minutes to build.
My sympathies to anyone who has to use async-stripe. Days of your life gone.
During the development of Learnix operating system I needed to represent bitflags inside some structures.
While there were alternatives with 3rd party libraries, the goal of the project is to implement and learn as much as I can.
Most of the guides I found online explained the concept great, but created only a simple macro as an example. So I decided to write about it myself too, with a real usage to create a bitfields attribute proc-macro, that takes a struct and turns it into bitfields.
As someone who has spent a _lot_ of time writing declarative and procedural macros, the important thing to ask before digging into a macro is whether you need a procedural macro at all.
Complex proc macros absolutely do slow builds down. In many cases, a proc macro only need to be a stub that can delegate to a declarative macro.
You may not need to use syn/quote, but if you are doing any sort of processing/parsing of Rust code you pretty much need to.
FWIW, I really hope that the Rust project focused on finer-grained token matching in declarative macros so we can migrate most proc_macro code away. The macro system is powerful, but nowhere near where it needs to be.
It's interesting seeing this discussion in Rust because it's the same discussion that's been happening around macros in Scheme for decades. It's one of those things or there probably is no universal correct answer, so might as well allow both in your language and let the programmer decide what's best for their case.
Yea that's sound about right
The macro explained in that section was mainly for me to learn macros, and save up some boilerplate with nice syntax.
Great writeup! Apologies if it came across as a criticism of the writeup itself, more of a frustration of years in the proc_macro space.
It's surprising how little information exists out there about proc_macros in general.
Thanks!
Couldn't agree more, both on proc macros and operating system, I did not find sufficient information on the internet. That is exactly the purpose of this book.
> FWIW, I really hope that the Rust project focused on finer-grained token matching in declarative macros so we can migrate most proc_macro code away. The macro system is powerful, but nowhere near where it needs to be.
I'm sick of how slow it is.
There has to be a more appropriate DSL for something like Serde that doesn't make big API surface area apps take ten minutes to build.
My sympathies to anyone who has to use async-stripe. Days of your life gone.
During the development of Learnix operating system I needed to represent bitflags inside some structures.
While there were alternatives with 3rd party libraries, the goal of the project is to implement and learn as much as I can.
Most of the guides I found online explained the concept great, but created only a simple macro as an example. So I decided to write about it myself too, with a real usage to create a bitfields attribute proc-macro, that takes a struct and turns it into bitfields.
Hope you will have a great read!
Very nice writeup, thank you for the time and effort!
Thanks for the warming comment!