cargo doc is Cargo’s command-line tool for generating browsable documentation for Rust packages and their dependencies. Running cargo doc --open builds the documentation and opens it in a browser, making unfamiliar Rust code easier to explore. section 13.1 section 18.4
Use cargo doc to:
- Create documentation with a layout that is familiar across the standard library and external crates. section 18.4
- Inspect structs, methods, automatically implemented traits, and blanket implementations. section 18.4
- Display documentation comments written with /// above structs, functions, and methods. section 18.4
- Use --no-deps when you want to document only your own code rather than its dependencies. section 18.4
Documenting a tiny crate
Add documentation comments to a small Rust API, then run cargo doc --open. For example, a DoesNothing struct and a PrintThing struct with a prints_something method appear in the generated pages. The documentation also reveals traits supplied automatically, while the /// comments explain the structs and method to readers. section 18.4
pub struct DoesNothing {}
pub struct PrintThing {}
impl PrintThing {
pub fn prints_something() {
println!("I am printing something");
}
}
This minimal listing gives cargo doc a struct and a method to display in its generated documentation. section 18.4

