liveBook · Manning

Identifier fragment specifier

An identifier fragment specifier is Rust declarative macro syntax that matches an identifier token, such as a variable or function name.

How 2 Manning books explain it

Learn Rust in a Month of Lunches

An identifier fragment specifier matches a Rust identifier such as a variable or function name as macro input.

How it is used
Uses ident in macro_rules! patterns to capture names for generated Rust code.
How deep it goes
Defines ident through focused macro examples but defers the complete fragment-specifier details.
Examples
Demonstrates identifier matching with x, my_vec, print_it, and say_its_nice.
What you can do after
Apply it via macro_rules! to capture variable or function names and reuse them in generated code.

Read how Learn Rust in a Month of Lunches explains identifier fragment specifier →

Write Powerful Rust Macros

An identifier fragment specifier matches an identifier token as an input fragment in a Rust declarative macro.

How it is used
Reduces repeated implementation code when declarative macros generate methods for named structs and newtypes.
How deep it goes
Explains identifier-token matching through a working macro and contrasts it with adding a `ty` fragment for return types.
Examples
Uses `FirstName`, `LastName`, `Age`, and `Pay` with a generated `get_value` method.
What you can do after
Build declarative macros that accept struct or type names and emit implementations using those captured identifiers.

Read how Write Powerful Rust Macros explains identifier 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.