This is a draft cheat sheet. It is a work in progress and is not finished yet.
Uses
format!("Hello {}", "World!"); // Returns a formatted string from a fmtstr.
let mut vec = vec![""];
// Destination (first arg) must &impl mut io::Write or a &impl mut fmt::Write
write!(&mut vec, "Hello {}", "World!"); // Writes a fmtstr
writeln!(&mut vec, "Hello Me!"); // write! but appends a newline
print!("Hello {}", "World!"); // Prints a fmtstr to stdout
println!("Hello {}", "World!"); // print! but appends a newline
eprint!("Hello {}", "World!"); // Prints a fmtstr to stderr
eprintln!("Hello {}", "World!"); // eprint! but appends a newline
format_args!("Hello {}", "World!"); // Returns fmt::Arguments, see https://doc.rust-lang.org/std/fmt/#format_args
|
|
|
Specifying Arguments
All format macros start with a format string, with the exception of write!
and writeln!
requiring a additional destination argument. It can contain a number of formats specified below. Positional arguments are specified immediately after, and then named arguments in the ident = val
format. |
Referencing Arguments
|
Next positional argument1 |
|
n-th positional argument, starting from 0 |
|
"ident" named argument, if nonexistent "ident" variable from the scope |
|
|
|
|
1 Ex. The second usage of {}
would be the second positional argument.
|