在这篇文章【译】用 Rust 实现 csv 解析-part4 中看到了一个新的写法:👇
fn run() -> Result<(), Box<Error>> {
let mut rdr = csv::Reader::from_reader(io::stdin());
for result in rdr.deserialize() {
let record: Record = result?;
println!("{:?}", record);
// 如果你不喜欢所有的内容缩卷到一行,可以试试下面这个打印:
// println!("{:#?}", record);
}
Ok(())
}
即 println!("{:#?}", record);
中的 #
,在看 Rust
官方关于 print
的文档(Formatted print)的时候,并没有 #
的内容。👇
Printing is handled by a series of macros defined in std::fmt some of which include:
format!: write formatted text to String print!: same as format! but the text is printed to the console (io::stdout). println!: same as print! but a newline is appended. eprint!: same as format! but the text is printed to the standard error (io::stderr). eprintln!: same as eprint!but a newline is appended.
但是在 Module std::fmt 看到了 format!
有相关的内容👇
format!("Hello"); // => "Hello"
format!("Hello, {}!", "world"); // => "Hello, world!"
format!("The number is {}", 1); // => "The number is 1"
format!("{:?}", (3, 4)); // => "(3, 4)"
format!("{value}", value=4); // => "4"
format!("{} {}", 1, 2); // => "1 2"
format!("{:04}", 42); // => "0042" with leading zeros
format!("{:#?}", (100, 200)); // => "(
// 100,
// 200,
// )"
println 内部调用了 format。