Fragment specifier
A fragment specifier is a declarative-macro matcher annotation that specifies the syntactic category of tokens a metavariable can match.
Write Powerful Rust Macros
A fragment specifier is the annotation in a declarative macro matcher that selects the syntactic category accepted by a metavariable.
- How it is used
- Selects the syntactic categories accepted by metavariables in declarative macro matchers.
- How deep it goes
- Explains common categories and the precision trade-off between concrete specifiers and TokenTree matching.
- Examples
- Uses expression capture to build vectors and contrasts concrete fragment matching with broad TokenTree matching.
- What you can do after
- Apply via declarative macros by choosing fragment specifiers that constrain inputs and testing broader TokenTree matchers carefully.
Read how Write Powerful Rust Macros explains fragment specifier →
Learn Rust in a Month of Lunches
A fragment specifier is a macro pattern annotation that declares what syntactic category of token input a metavariable can match.
- How it is used
- Guides macro input matching by restricting metavariables to chosen syntactic categories.
- How deep it goes
- Explains matching with expression and statement examples, then lists the available specifiers without requiring memorization.
- Examples
- Uses `$input:expr` with values and vectors, contrasts it with `$input:stmt`, and demonstrates `ident` and `tt` patterns.
- What you can do after
- Build macro_rules! patterns that accept appropriately categorized input and interpret compiler matching errors.
Read how Learn Rust in a Month of Lunches explains fragment specifier →
Related concepts
- metavariableequivalent to · A metavariable is a declarative-macro binding whose fragment specifier determines the syntactic category of captured input.
- type fragment specifierincludes · A type fragment specifier is a declarative-macro matcher specifier that matches Rust type syntax.
- macroconfigures · A macro is a named construct that expands or transforms source code, commands, or templates before or during execution.
- token treeused by · A token tree is a recursive Rust macro syntax structure consisting of tokens and nested delimited sequences of tokens.
- expression fragment specifiercontrasts with · An expression fragment specifier is a Rust declarative-macro matcher annotation that matches syntax representing an expression.
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.

