Can macro compose names from its arguments?



I want to make a macro that generates a function name from its arguments.

macro_rule! example {
    ($i:ident) => (
        fn example_$i() {
            // some code

example!(AA); // => I want it to generate function example_AA

Is it possible?


There’s concat_idents! but that notes its own limitations. AFAICS it doesn’t work for declaring a function.

Edit: see


Yes, I tried concat_idents, that can generate identifiers already defined, but cannot define…

Thank you.


concat_idents! is probably not being stabilized.

For inspirations to tackle this problem using modules, see here: