第9章 可调试性

可调试性 — Rust API Guidelines

译文 · 基于 Rust API Guidelines

原文链接: https://rust-lang.github.io/api-guidelines/debuggability.html

可调试性

所有公开类型实现 Debug (C-DEBUG)

即便有例外,也极为少见。

Debug 表示永不空 (C-DEBUG-NONEMPTY)

即便对于概念上为空的值,Debug 表示也永不应当为空。

1
2
3
4
5
let empty_str = "";
assert_eq!(format!("{:?}", empty_str), "\"\"");

let empty_vec = Vec::<bool>::new();
assert_eq!(format!("{:?}", empty_vec), "[]");
最后修改 August 21, 2026: 更新 (76fc81a2e)