macro_metavar_expr_concat
The tracking issue for this feature is: #124225
In stable Rust, there is no way to create new identifiers by joining identifiers to literals or other identifiers without using procedural macros such as paste
.
#![feature(macro_metavar_expr_concat)]
introduces a way to do this, using the concat metavariable expression.
This feature uses the syntax from
macro_metavar_expr
but is otherwise independent. It replaces the since-removed unstable featureconcat_idents
.
This is an experimental feature; it and its syntax will require a RFC before stabilization.
Overview
#![feature(macro_metavar_expr_concat)]
provides the concat
metavariable expression for creating new identifiers:
This macro invocation expands to:
Syntax
This feature builds upon the metavariable expression syntax ${ .. }
as specified in RFC 3086 (macro_metavar_expr
).
concat
is available like ${ concat(items) }
, where items
is a comma separated sequence of idents and/or literals.
Examples
Create a function or method with a concatenated name
This expands to:
Create names for macro generated tests
Running this returns the following output:
running 6 tests
test test_i32_subtraction ... ok
test test_i32_addition ... ok
test test_u128_addition ... ok
test test_u128_subtraction ... ok
test test_u64_addition ... ok
test test_u64_subtraction ... ok
test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s