macro_rules! format { ($($arg:tt)*) => { ... };}Expand description
Creates aString using interpolation of runtime expressions.
The first argumentformat! receives is a format string. This must be a stringliteral. The power of the formatting string is in the{}s contained.Additional parameters passed toformat! replace the{}s within theformatting string in the order given unless named or positional parametersare used.
Seethe formatting syntax documentation instd::fmtfor details.
A common use forformat! is concatenation and interpolation of strings.The same convention is used withprint! andwrite! macros,depending on the intended destination of the string; all these macros internally useformat_args!.
To convert a single value to a string, use theto_string method. Thiswill use theDisplay formatting trait.
To concatenate literals into a&'static str, use theconcat! macro.
§Panics
format! panics if a formatting trait implementation returns an error.This indicates an incorrect implementationsincefmt::Write for String never returns an error itself.