liveBook · Manning

Macro recursion

Macro recursion is macro-expansion behavior in which a macro expands to another invocation of itself.

How 2 Manning books explain it

Write Powerful Rust Macros

Macro recursion is the expansion behavior in which a macro invocation expands to another invocation of the same macro.

How it is used
Uses recursive expansion to delegate macro patterns and reduce repeated generated implementations.
How deep it goes
Explains recursive expansion through working macro arms and a compile-time failure, but defers unknown-argument recursion to another example.
Examples
Demonstrates recursive `generate_get_value!` delegation and a failing `count!` macro that expands indefinitely.
What you can do after
Apply it via `macro_rules!` to route simpler invocations into generalized implementations while recognizing expansion-time recursion failures.

Read how Write Powerful Rust Macros explains macro recursion →

Learn Rust in a Month of Lunches

Macro recursion is a macro-expansion technique in which a macro invokes itself to process or handle additional input.

How it is used
Uses self-invocation to process or normalize additional macro input before reaching a terminating expansion.
How deep it goes
Shows recursive macro arms and a base case, but stops short of explaining the complete expansion process.
Examples
Uses my_macro!, write!, format_args!, and todo! to illustrate recursive calls, argument forwarding, and macro inputs.
What you can do after
Evaluate macro-recursive behavior by tracing input-matching arms toward the terminating expansion.

Read how Learn Rust in a Month of Lunches explains macro recursion →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.