Printing

print! and println! macros to write to stdout. There is also format! to write to a string.

Simple types can be printed with display formatting {}. More complex types can be printed with debug formatting {:?}.

Display formatting requires implementing std::fmt::Display.

{:#?} is pretty-printing.

Easy Rust printing

Named substitution


#![allow(unused)]
fn main() {
println!(
        "{city1} is in {country} and {city2} is also in {country},
but {city3} is not in {country}.",
        city1 = "Seoul",
        city2 = "Busan",
        city3 = "Tokyo",
        country = "Korea");
}

Substitution format

{variable:padding alignment minimum.maximum}

e.g. {city1:0<5.15}

More Printing