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 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
.
Why am I not surprised the crate was authored by @dtolnay?
Paste wasn't the first try: mashup
.
But yes, I'm appreciative of all that dtolnay has done for the Rust community .
I gave up, I wrote traits to avoid type name in function names...
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.