Closed Xephobia closed 3 years ago
The #[command(""$x"")]
bit fails because it put space around the expr, I don't know if it is really the issue, but it is unintended
You could do it like this:
macro_rules! gen_random_funs {
($($x:ty),*) => {
$(
paste!(gen_random_funs! {
#[command = "" $x]
#[description = "generates a random `" $x "`"]
async fn [<_ $x>](ctx: &Context, msg: &Message) -> CommandResult {
msg.reply(ctx, rand::random::<$x>()).await?;
Ok(())
}
});
)*
};
(#[command = $command:literal] $fn:item) => {
#[command($command)]
$fn
};
}
This works, thanks! We should leave the issue open until there is a fix for the og code.
I think there doesn't need to be any change made in paste. #[attr("..." $x "...")]
is already a syntactically valid attribute so it doesn't make sense for paste to mess with it. #[attr = "..." $x "..."]
is syntactically invalid so that's the signal for paste to apply the concatenation of the strings into a single literal.
regarding this code :
this fails with all the argument, quote
unexpected token
, note that macro also fail to expand in attributes inpaste!
blocks, this prevents the use ofstringify!
and such.