Declarative Macros

This chapter will introduce Rust's declarative macro system: macro_rules!.

There are two different introductions in this chapter, a methodical and a practical.

The former will attempt to give you a complete and thorough explanation of how the system works, while the latter one will cover more practical examples. As such, the methodical introduction is intended for people who just want the system as a whole explained, while the practical introduction guides one through the implementation of a single macro.

Following up the two introductions it offers some generally very useful patterns and building blocks for creating feature rich macros.

Other resources about declarative macros include the Macros chapter of the Rust Book which is a more approachable, high-level explanation as well as the reference chapter which goes more into the precise details of things.

Note: This book will usually use the term mbe(Macro-By-Example), mbe macro or macro_rules! macro when talking about macro_rules! macros.