Guidelines for writing Rust documentation
Standards to follow when writing Rust documentation.
# Safety section, link the word valid to std's pointer-validity rules: write it as
[valid] and put this reference definition at the end of the doc block —[valid]: https://doc.rust-lang.org/std/ptr/index.html#safety
Only where it means pointer or memory validity — valid UTF-8, a valid enum variant, a valid
nul terminator and a by-value struct whose fields must agree keep their plain form, since
std's definition says nothing about them.
A duration clause such as "must remain valid for the lifetime of the returned iterator" does
mean it, so link it as well; the duration it adds is orthogonal to what validity means.
A callback parameter is the other way round: std's rules cover accesses through data
pointers, not whether an address is callable under a given ABI, so require the signature
to be [ABI-compatible] instead and define it as —[ABI-compatible]: https://doc.rust-lang.org/std/primitive.fn.html#abi-compatibility
Non-doc // SAFETY: comments keep the plain form too: rustdoc does not render them, so the
brackets would stay literal text.#[allow(rustdoc::private_intra_doc_links)] where relevant.