I want to take a part of a field name in a macro, and then use it concatenated with the other part.
Here is an example in C:
#define MY_MACRO(NAME) cout << mystruct->foo_##NAME << endl;
I tried this:
macro_rules! MY_MACRO {
($NAME:ident) => {
println!("{}", mystruct.concat_idents!(foo_, $NAME);
}
}
But I get this:
error: expected one of `(`, `,`, `.`, `::`, `?`, or an operator, found `!`
--> macrotest.rs:12:46
|
12 | println!("{}", mystruct.concat_idents!(foo_, $NAME));
| ^ expected one of `(`, `,`, `.`, `::`, `?`, or an operator
...
16 | MY_MACRO!(bar);
| --------------- in this macro invocation
|