Before we build more complex macros, it's important to become familiar with the valid inputs that macro_rules! can take. Since macro_rules! work at the syntactic level, it needs to provide users, a handle to these syntactic elements, and distinguish what can and cannot be included within a macro and how we can interact with them.
The following are some important token tree types that you can pass into a macro as input:
- block: This is a sequence of statements. We have already used block in the debugging example. It matches any sequence of statements, delimited by braces, such as what we were using before:
{ silly; things; }
This block includes the statements silly and things.
- expr: This matches any expression, for example:
- 1
- x + 1
- if x == 4 { 1 } else { 2 }
- ident: This matches an identifier. Identifiers are any unicode strings that are not...