| name | rustdoc |
| description | Rust documentation conventions (RFC 1574). Apply when writing doc comments on public Rust items. Covers summary sentences, section headings, type references, and examples. |
Rust Documentation Conventions (RFC 1574)
Apply these rules when writing doc comments (///) on public Rust items.
Summary Sentence
Every doc comment starts with a single-line summary sentence.
Comment Style
Use line comments, not block comments.
Use //! only for crate-level and module-level docs at the top of the file.
Section Headings
Use these exact headings (always plural):
Type References
Use full generic forms and link with reference-style markdown.
Examples
Every public item should have examples showing usage.
pub fn add(a: i32, b: i32) -> i32 {
a + b
}
For multiple patterns:
Errors Section
Document what errors can be returned and when.
Panics Section
Document conditions that cause panics.
pub fn divide(dividend: i32, divisor: i32) -> i32 {
assert!(divisor != 0, "divisor must not be zero");
dividend / divisor
}
Safety Section
Required for unsafe functions.
pub unsafe fn deref<'a, T>(ptr: *const T) -> &'a T {
&*ptr
}
Module vs Type Docs
- Module docs (
//!): high-level summaries, when to use this module
- Type docs (
///): comprehensive, self-contained
Some duplication is acceptable.
Language
Use American English spelling: "color" not "colour", "serialize" not "serialise".