Macro std::fmt::format_args
Transforms a format string and arguments into a sequence of chunks.
This macro is implemented in the compiler, and is used as a foundation for other formatting macros, such as format and println. You probably want to use one of those formatting macros instead.
format_args!(receiver, "{} = {}", a, b); // Expands to: receiver!(a, " = ", b)
Examples
use std::fmt::format_args;
use std::concat;
// This only works where all format arguments are string literals.
let s = format_args!(concat, "{} + {} = {}", "1", "2", "3");
assert_eq!(s, "1 + 2 = 3");
Run this example
use std::fmt::format_args;
use std::typing::type_name;
macro debug($arg...) {
{
let arg = $arg;
println!("'{}' {}", arg, type_name::<typeof(arg)>());
}$...;
}
// '1' i32
// ' + ' &[u8]
// '2' i32
// ' = ' &[u8]
// '3' i32
format_args!(debug, "{} + {} = {}", 1, 2, 3);
Run this example