liveBook · Manning

Fragment specifier

A fragment specifier is a declarative-macro matcher annotation that specifies the syntactic category of tokens a metavariable can match.

How 2 Manning books explain it

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

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.