Macros: how to I append $t:ty to a function name

I have a macro like this:

($($t:ty)*) => {$(
        fn function_for_$t(v: $t) {...}
)*}

But it won't compile, since $t cannot be appended to function_for_, so how can I do this right?

I tried to do this last week but gave up.

You may be interested in a crate like paste.

2 Likes

Why am I not surprised the crate was authored by @dtolnay?

3 Likes

Paste wasn't the first try: mashup.

But yes, I'm appreciative of all that dtolnay has done for the Rust community :slightly_smiling_face:.

I gave up, I wrote traits to avoid type name in function names...

1 Like

In principle you could just use a $ty:ident argument instead of a $t:ty argument.

Of course that would also allow non-types to be passed in, since any identifier is valid.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.