Why can't format! be used in the procedure macro?
already use std::fmt;
Why can't format! be used in the procedure macro?
already use std::fmt;
It's best to use globally qualified paths in your macro for all type references. This will avoid ambiguities caused by name collisions with other types in the namespace where the macro is expanded.
format!
exists at ::std::format!
, not ::std::fmt::format!
:
macro_rules! hello {
($x:expr) => {
::std::format!("Hello, world! {}", $x)
}
}
fn main() {
println!("{}", hello!(123 + 456));
}
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.