Write good Rust crate documentation by using rustdoc comments to generate API docs and mdbook to build user guides. Add /// comments above public items for API documentation and create a book.toml file to configure the book structure.
[package]
name = "my_crate"
version = "0.1.0"
edition = "2024"
[dependencies]
/// Adds two numbers together.
pub fn add(a: i32, b: i32) -> i32 {
a + b
}
[book]
title = "My Crate Guide"
authors = ["Your Name"]
[output.html]
cargo doc --open
mdbook build
- Add
///comments above public functions, structs, and modules to describe their purpose and usage. - Create a
book.tomlfile in the root directory to define the book title, authors, and output settings. - Run
cargo doc --opento generate and view the API documentation in your browser. - Run
mdbook buildto compile the user guide from markdown files in thesrcdirectory.