liveBook · Manning

Token tree

A token tree is a recursive Rust macro syntax structure consisting of tokens and nested delimited sequences of tokens.

How 3 Manning books explain it

Write Powerful Rust Macros

A Rust token tree is a syntactic token or delimited sequence of tokens that can be captured as a broadly permissive macro fragment.

How it is used
Captures and forwards broadly shaped macro input when narrower declarative fragments cannot express it.
How deep it goes
Defines TokenTrees within TokenStreams and demonstrates matcher capture and direct procedural-macro inspection, while deferring complete syntax parsing.
Examples
Uses a `lazy_static!` trailing matcher and a derive macro that extracts a struct or enum name.
What you can do after
Apply it via `macro_rules!` matchers or procedural TokenStream iteration when macro input must be captured or inspected.

Read how Write Powerful Rust Macros explains token tree →

Idiomatic Rust

A token tree is a recursive syntactic structure containing tokens, sequences of tokens, or nested token trees for macro matching.

How it is used
Supports variadic macro matching and forwards arbitrary argument token sequences to another macro.
How deep it goes
Defines recursive token trees, repetition quantifiers, and transcription, but does not develop broader macro parsing internals.
Examples
Uses special_println!, println!, format!, format_args!, and var_print! to demonstrate capture, forwarding, and repeated identifiers.
What you can do after
Build macro_rules! matchers that capture repeated token trees and replay them in an expansion.

Read how Idiomatic Rust explains token tree →

Learn Rust in a Month of Lunches

A token tree is a syntactic token or delimited group of tokens that can be matched and repeated by a Rust macro.

How it is used
Explains how declarative macros accept and repeat flexible input.
How deep it goes
Defines `tt` and demonstrates repetition, but stops short of compiler internals behind built-in macros.
Examples
Uses `write!`, `format_args!`, and `todo!` to show single, repeated, empty, and formatted token-tree inputs.
What you can do after
Evaluate macro definitions to infer whether they accept one, many, optional, or formatted inputs.

Read how Learn Rust in a Month of Lunches explains token tree →

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.