macro_rules! fmt_args { ($($tt:tt)+) => { ... }; }
Expand description
Like core::format_args!
, but with full ownership.
Examples
use std::fmt::Display;
fn format(a: String, b: String) -> impl Display {
fmty::format_args!("{a} + {b}")
}
let value = format(1.to_string(), 2.to_string());
assert_eq!(value.to_string(), "1 + 2");
Like core::format_args!
, the result implements Debug
.
let value = fmty::format_args!("{a} + {b}");
let debug = format!("{:?}", value);
assert_eq!(debug, "1 + 2");
This macro is also aliased as fmt_args
for optional brevity.
fmty::fmt_args!("{a} + {b}")
Limitations
Because of how this macro is implemented, nested invocations cannot be implicitly owned.
ⓘ
let s: String = "hola".to_owned();
let value = fmt_args!("{}", fmt_args!("{}", s));
To work around this, the inner value must be explicitly binded:
let inner = fmty::format_args!("{}", s);
let value = fmty::format_args!("{}", inner);