发布于 2020-07-28 04:49:02
Display的输出通常比Debug的更干净,而不是实现它的代码。debug的输出将用于调试目的,从而提供一个不那么含糊的输出。Display的输出是面向用户的输出,因此它高度依赖于您的结构的含义,这就是不能导出它的原因。
例如,考虑以下代码:
fn main() {
// Note that \t is the TAB character
let output = "N\tO\tI\tC\tE";
println!("Debug: {:?}", output);
println!("Display: {}", output);
}它将输出:
Debug: "N\tO\tI\tC\tE"
Display: N O I C E在本例中,Debug将显示str (text)包含的字符(在调试时更有用),而Display将只打印它们。
https://stackoverflow.com/questions/63126859
复制相似问题