[−][src]Trait dyn_fmt::AsStrFormatExt
Extends strings with the format
method, which is a runtime analog of the format!
macro.
Unavailable in no_std
environment.
Provided methods
fn format<'a, T: Display + ?Sized + 'a>(
&self,
args: impl IntoIterator<Item = &'a T> + Clone
) -> String
&self,
args: impl IntoIterator<Item = &'a T> + Clone
) -> String
Creates a String
replacing the {}s within self
using provided parameters in the order given.
A runtime analog of format!
macro. In contrast with the macro format string have not be a string literal.
Examples:
use dyn_fmt::AsStrFormatExt; assert_eq!("{}a{}b{}c".format(&[1, 2, 3]), "1a2b3c"); assert_eq!("{}a{}b{}c".format(&[1, 2, 3, 4]), "1a2b3c"); // extra arguments are ignored assert_eq!("{}a{}b{}c".format(&[1, 2]), "1a2bc"); // missing arguments are replaced by empty string assert_eq!("{{}}{}".format(&[1, 2]), "{}1");