-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Allow tt
at format string position
#15
Comments
For now, I use the following workaround: macro_rules! say{
($id:expr, $fmt_str:literal $(, $arg:expr)*) => {{
bunt::print!(
"{$blue}[{}][{}]{/$} ",
BIN.get().expect("Usage before static variable `BIN` set"),
$id
);
bunt::println!($fmt_str $(, $arg)*)
}};
}
macro_rules! err{
($id:expr, $fmt_str:literal $(, $arg:expr)*) => {{
bunt::print!(
"{$red}[{}][{}]{/$} ",
BIN.get().expect("Usage before static variable `BIN` set"),
$id
);
bunt::println!($fmt_str $(, $arg)*)
}};
} But I think |
This is actually something I already thought about, precisely for the same reason: I have another wrapper macro that wants to pass a
Exactly and that's the problem. There is a relevant RFC that's not merged yet: rust-lang/rfcs#2320 But in the meantime, we could allow multiple string literals in that position. I.e. to allow |
That's unfortunate, eager expansion would make more sense, IMO (but there are most likely good reasons, why it was implemented this way initially).
Yes, that would be a good workaround, that probably covers most use cases. What do you think about With a match arm that matches a tuple in the first position, it should be easy to collect the values and pass them to |
Hi,
At the moment
bunt
only allows literals at the format string position.std:println
, however, allowstt
.Unfortunately, this prevents
bunt
users from generating format strings via macros.For example, I tried the following:
Because
concat!("{$", $color, "}[{}][{}]{/$} ", $fmt_str)
isn't a literal, this code doesn't compile.std
allows this, however (Playground:From looking at the source code (see links above), it seems
bunt
would just have to replaceliteral
in$format_str:literal
withtt
to support this.Maybe the
tt
would have to be converted to a literal somehow, I'm not sure. The macros above are the only macros I have created so far :)The text was updated successfully, but these errors were encountered: