A fragment specifier tells a declarative macro matcher which Rust syntactic category a metavariable may capture. For example, $x:expr captures one expression, while ident captures an identifier or keyword. section 2.1.4
Choose the narrowest fragment category that fits the macro input:
- Use expr for expressions and ident for identifiers; other categories include block, item, literal, and type. section 2.1.4
- Use tt, or TokenTree, when the matcher must accept almost anything, but expect less precise checking and test carefully. section 2.1.4
Capturing an expression
A matcher such as {$x:expr} accepts one expression and binds it to x, allowing the expansion to push that value into a newly created vector. section 2.1.4
{$x:expr} => {
{
let mut v = Vec::new();
v.push($x);
v
}
};
Inspect the expression matcher and its expansion, including the metavariable binding and generated vector operations. section 2.1.4

