compose-idents
A procedural macro that allows to construct identifiers from one or more arbitrary parts.
Motivation
Rust's declarative macros do not allow generating new identifiers, because they are designed to operate on the syntactic level (as opposed to the lexical level) using simple pattern matching.
For example the following code won't work:
my_macro!;
This is why there is a need for a macro that allows to construct new identifiers.
Usage
Here is how the macro works:
use compose_idents;
compose_idents!;
assert_eq!;
assert_eq!;
Here is a more practical example for how to auto-generate names for macro-generated tests for different data types:
use Add;
use compose_idents;
generate_add_tests!;
test_add_u8;
test_add_u32;
test_add_u64;
For more usage examples look into examples/ and tests/ directories of the repository.
Alternatives
There some other projects dedicated to identifier manipulation:
- A very similar macro that doesn't support multiple aliases and is not maintained: https://github.com/DzenanJupic/concat-idents
- A macro that allows to define and refer to unique temporary variables: https://crates.io/crates/templest
Development
The following standards are followed to maintain the project: