Procedural macros

While regular syntactic macros are useful in a number of scenarios, some applications need advanced code generation features that are better done using the AST that the compiler operates on. Thus, there was a need to extend the macro system to include this. It was later decided that the old macro system and this new system called procedural macros would co-exist. Over time, this is intended to replace the syntactic macro system. The compiler supports loading plugins from external crates; these can receive the AST once the compiler has generated it. There are APIs available to modify the AST in-place to add new code as required. A detailed discussion of this system is beyond the scope of this book.

Get Network Programming with Rust now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.