Documenting and publishing a Rust crate
Answer: The crate registry at crates.io distributes the source code of your packages. It primarily hosts code that is open source. Documentation comments use three slashes and support Markdown notation. Cargo doc builds HTML documentation. Cargo test --doc runs only documentation tests.
Comments, HTML docs, and crates.io
The registry at crates.io distributes the source code of your packages.
It primarily hosts code that is open source.
Documentation comments use three slashes instead of two.
They also support Markdown notation for formatting the text.
You can generate the HTML documentation from this documentation comment by running cargo doc.
cargo doc and documentation tests
Use cargo doc to build documentation in target/doc.
The --open flag will automatically open that documentation in your web browser.
Doc comments are denoted by ///, and support Markdown.
Use cargo test to run all tests, including documentation tests.
Pass cargo test --doc to only run documentation tests.
See also
Claims
- id: C1 claim: crates.io distributes package source and primarily hosts open source code. source: S1 evidence: "primarily hosts code that is open source"
- id: C2 claim: Documentation comments use three slashes and support Markdown. source: S1 evidence: "use three slashes, /// , instead of two and support Markdown"
- id: C3 claim: cargo doc builds documentation in target/doc. source: S2 evidence: "build documentation in target/doc"
- id: C4 claim: cargo test --doc runs only documentation tests. source: S2 evidence: "cargo test --doc to only run documentation tests"
Sources
- [S1] Publishing a Crate to Crates.io. The Rust Programming Language. https://doc.rust-lang.org/book/ch14-02-publishing-to-crates-io.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.
- [S2] Documentation. Rust By Example. https://doc.rust-lang.org/rust-by-example/meta/doc.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, Publishing a Crate to Crates.io; Rust By Example, Documentation. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/LICENSE-MIT). Copyright the Rust Project Developers. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, Publishing a Crate to Crates.io; Rust By Example, Documentation. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/LICENSE-MIT). Copyright the Rust Project Developers.
Cite this
iinventedlight. 2026. "Documenting and publishing a Rust crate." iinventedlight Library, iil:note:1r8nwdt1, version of 2026-11-23. https://iinventedlight.com/library/notes/rust-publishing-crates/. License: CC-BY-4.0.
@misc{iil_note_1r8nwdt1,
author = {{iinventedlight}},
title = {{Documenting and publishing a Rust crate}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/rust-publishing-crates/},
note = {Permanent ID iil:note:1r8nwdt1. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- rust-publishing-crates.schema.json (schema; CC-BY-4.0)
- rust-publishing-crates.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/rust-publishing-crates.md.