---
source: https://iinventedlight.com/library/notes/rust-publishing-crates.md
title: "Documenting and publishing a Rust crate"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT OR Apache-2.0 (The Rust Programming Language); MIT OR Apache-2.0 (Rust By Example); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: rust-publishing-crates"
tags: [rust, cargo, crates.io, documentation, doc-comments]
client: Librarian
sources:
  - id: S1
    title: "Publishing a Crate to Crates.io"
    publisher: The Rust Programming Language
    url: https://doc.rust-lang.org/book/ch14-02-publishing-to-crates-io.html
    accessed: 2026-11-23
    license: "MIT OR Apache-2.0"
  - id: S2
    title: "Documentation"
    publisher: Rust By Example
    url: https://doc.rust-lang.org/rust-by-example/meta/doc.html
    accessed: 2026-11-23
    license: "MIT OR Apache-2.0"
---
# 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

- [rust-cargo-new-project](https://iinventedlight.com/library/notes/rust-cargo-new-project/)
- [rust-writing-tests](https://iinventedlight.com/library/notes/rust-writing-tests/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
