cargo-rustdoc
Generate documentation for Rust projects
TLDR
Pass options to rustdoc
Warn about a documentation lint
Ignore a documentation lint
Document the package's library
Document the specified binary
Document the specified example
Document the specified integration test
SYNOPSIS
cargo-rustdoc [OPTIONS] [--] [<PATH>]
PARAMETERS
--open
Automatically opens generated docs in default browser
--no-deps
Document only the specified packages, skipping dependencies
--document-private-items
Includes private items (re-exported or not) in docs
-p SPEC, --package SPEC
Package(s) to document (e.g., 'foo', 'foo:0.1.0')
--lib
Document only library targets
--bins
Document all binary targets
--examples
Document all example targets
--tests
Document all test targets
--target TRIPLE
Target triple for documentation
--manifest-path PATH
Path to Cargo.toml
--workspace
Document all packages in workspace
--all-features
Build with all features enabled
--jobs N
Number of parallel jobs (default: number of CPUs)
--target-dir DIR
Output directory for target files
-h, --help
Prints help information
DESCRIPTION
The cargo-rustdoc command is a Cargo subcommand that builds HTML documentation for Rust packages (crates) using the rustdoc compiler. It processes Rust source code comments to create navigable API docs, including search, source links, and dependency graphs. Output is placed in target/doc by default.
Ideal for developers publishing to crates.io or maintaining local references, it handles workspaces, dependencies, and cross-compilation. Runs rustdoc on the library, binaries, examples, tests, or benches as specified. Shares Cargo's build system for reproducible, incremental builds.
Flags control scope (e.g., no deps, private items), presentation (--open launches browser), and configuration (features, targets). Integrates seamlessly with Cargo.toml profiles. Requires rustdoc from Rust toolchain (install via rustup component add rustdoc). Essential for Rust ecosystem documentation.
CAVEATS
Requires rustdoc toolchain component. Docs built for current profile (dev by default); use Cargo.toml [profile.dev.doc] for customizations. Incremental builds supported but may need cargo clean after changes. Not for Markdown books (use mdbook).
EXAMPLES
cargo-rustdoc --open
Builds and opens docs in browser.
cargo-rustdoc -p mycrate --lib
Documents specific library package.
cargo-rustdoc --no-deps --target wasm32-unknown-unknown
WebAssembly-targeted docs without deps.
EXIT STATUS
0: Success.
101: Invalid configuration.
Other: Compilation or I/O errors.
HISTORY
Part of Cargo since initial 0.1.0 release (2014, Rust 0.12 era). Developed by Mozilla/Yehuda Katz et al. Evolved with Rust stable (1.0, 2015); added --open (0.10), workspace support (0.18). Now core to Rust 1.80+ ecosystem, with improvements for async/no_std docs.
SEE ALSO
cargo(1), rustdoc(1), cargo-build(1), cargo-test(1), mdbook(1)


