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.
- expression fragment specifierincludes · An expression fragment specifier is a Rust declarative-macro matcher annotation that matches syntax representing an expression.
- macroconfigures · A macro is a named, reusable construct that expands into generated code or a sequence of commands when invoked, often during preprocessing, compilation, or application execution.
- token treekind of · A token tree is a recursive Rust macro syntax structure consisting of tokens and nested delimited sequences of tokens.
- identifier fragment specifierincludes · An identifier fragment specifier is Rust declarative macro syntax that matches an identifier token, such as a variable or function name.
- token-tree fragment specifierincludes · A token-tree fragment specifier is a Rust declarative-macro matcher specifier that matches a token tree, including delimited groups.
Questions about fragment specifier
What is fragment specifier?
A fragment specifier is a declarative-macro matcher annotation that specifies the syntactic category of tokens a metavariable can match.
Which Manning books explain fragment specifier?
Write Powerful Rust Macros and Learn Rust in a Month of Lunches.
What kinds of fragment specifier are there?
Kinds of fragment specifier include expression fragment specifier, identifier fragment specifier and token-tree fragment specifier.
What is fragment specifier a kind of?
Fragment specifier is a kind of token tree. A token tree is a recursive Rust macro syntax structure consisting of tokens and nested delimited sequences of tokens.
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.

