知识卡片

普通读书笔记卡 · 10883.b.1.b · 生成模型:未记录

格式化区分显示与调试

理解等级:中级

format! 生成新的 String,可用 format!("Hello, {place}!") 将变量插入文本。println! 采用相同的格式语法并负责输出。普通 {} 使用 Display;{:?} 使用 Debug,例如输出字符串时会带引号并转义特殊字符,元组、切片和向量通常也使用 Debug。输出字面花括号时写 {{ 或 }}。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第02章《Fundamental Types》|构造、格式化和拼接字符串,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch02.xhtml#string` - 结论依据:原文对照 format! 与 println!,并用相同字符串的两种输出解释 Display 与 Debug。 - 原始内容:A format specifier of {} or {name} renders a value in Display format, for end users; {:?} or {name:?} renders it in Debug format, for