-
Notifications
You must be signed in to change notification settings - Fork 256
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
Figure out macro invocation syntax for the new release #218
Comments
Is there a downside to the current syntax today? If so mind listing that out? |
The primary concern is how to fit parameters in. The matcher for the format arguments has to be (I think?) |
Oh right yes sorry! I think I misunderstood. |
Not proposing this as a solution, but it's perfectly possible to parse format args that are not the end of a level of nesting. macro_rules! info {
// public
(target: $t:expr, $fmt:expr) => {
info!([$fmt]);
};
(target: $t:expr, $fmt:expr, $($rest:tt)*) => {
info!([$fmt] $($rest)*);
};
// private
([$($fmt:tt)*]) => {
println!($($fmt)*);
};
([$($fmt:tt)*] params: { $($k:ident : $v:expr),* }) => {
println!($($fmt)*);
$(
println!("params[{}] = {:?}", stringify!($k), $v);
)*
};
([$($fmt:tt)*] params: { $($k:ident : $v:expr,)* }) => {
info!([$($fmt)*] params: { $($k : $v),* });
};
([$($fmt:tt)*] $n:ident = $v:expr) => {
info!([$($fmt)*, $n = $v]);
};
([$($fmt:tt)*] $n:ident = $v:expr, $($rest:tt)*) => {
info!([$($fmt)*, $n = $v] $($rest)*);
};
([$($fmt:tt)*] $v:expr) => {
info!([$($fmt)*, $v]);
};
([$($fmt:tt)*] $v:expr, $($rest:tt)*) => {
info!([$($fmt)*, $v] $($rest)*);
};
}
fn main() {
let foo = 0;
info!(target: "some_target", "foo: {}", foo, params: { foo: foo, bar: "hello" });
} |
Wow, you are a magician! I'm guessing we can move |
Nice! That actually seems like a pretty sweet API to me |
It seems to me that additional Pasted for conviniance:
The main point being that the first part (until |
I believe this is the last blocker on an 0.4 release. Are people okay with the syntax as it exists today? It seems like whether we go for |
Sounds plausible to me! |
It looks like the case. Are we happy to close this now or would you like to keep it open for a while longer? |
I think we're good to go. |
Use `opt-level = "z"` for release
There are a couple of constraints here, IMO:
println!(...)
intodebug!(...)
with no changes to the inner bit.The current syntax is as println with an optional
target: $expr,
at the start to specify the target. I don't really think that sticking things before the formatting part is going to work for parameters, so we'll need some other way of working with that.One possibility is that string interpolation isn't supported when providing parameters, since all of the dynamic info should be provided in the parameters. Not sure how people would feel about that though.
cc @alexcrichton @dtolnay @dpc
The text was updated successfully, but these errors were encountered: