When you implement Debug, Rust provides "pretty printing" with {:#?}. From the std::fmt documentation:
# - This flag indicates that the “alternate” form of printing should be used. The alternate forms are:
{:#?} - pretty-print the Debug formatting (adds linebreaks and indentation)
- [others omitted]
Example:
#[derive(Debug)]
struct Person {
name: &'static str,
age: u8,
hobbies: Vec<&'static str>,
}
fn main() {
let peter = Person {
name: "Jesse",
age: 49,
hobbies: vec!["crosswords", "sudoku"],
};
println!("{:#?}", peter);
}
Output:
Person {
name: "Jesse",
age: 49,
hobbies: [
"crosswords",
"sudoku",
],
}
Playground