Procedural Macros book

As nice as it would be, the community isn’t going to write a book on “everything that @dtolnay and @alexcrichton know about procedural macros” because practically none of this has ever been written down. :slightly_frowning_face:

I have found that there is a huge difference between what people think will be hard about procedural macros before writing any procedural macros, vs what actually is hard about procedural macros. It is easy to write a book about the former but I think doing so would be misguided.

As a basic concrete example, the ghost crate illustrates the distinction I am making. From a naive perspective this is a very simple macro – it parses some simple input using syn in a simple way and generates some simple output using quote in a simple way. How all of this happens is pretty uninteresting and someone could pick it up from an hour in the Syn docs and example code. Unfortunately I suspect this is what most people believe belongs in a procedural macro book. It belongs in syn and quote docs.

The resource missing is everything that does not belong in the syn and quote docs. This largely centers on patterns for what code to generate. This is where you find practically all of the relevant domain expertise for writing actual macros and is knowledge that transcends any specific how libraries like syn and quote.

6 Likes