cargo-doc

Generate documentation for a Rust package

TLDR

Build documentation
$ cargo doc
Build and open in browser
$ cargo doc --open
Build without dependencies
$ cargo doc --no-deps
Include private items
$ cargo doc --document-private-items
Build for all workspace members
$ cargo doc --workspace
Build with release profile
$ cargo doc --release
Build with all features
$ cargo doc --all-features

SYNOPSIS

cargo doc [options]

DESCRIPTION

cargo doc builds documentation for the local package and all dependencies using rustdoc. Output placed in target/doc/ in HTML format.

PARAMETERS

--open

Open documentation in browser after building
--no-deps
Don't build documentation for dependencies
--document-private-items
Include non-public items (default for binaries)
-r, --release
Build with release profile
--workspace
Document all workspace members
--exclude spec
Exclude packages (with --workspace)
-p, --package spec
Document specific packages
--lib
Document library only
--bins
Document all binaries
--target triple
Document for target architecture
-j, --jobs n
Parallel jobs (default: CPU count)
--features features
Enable specified features
--all-features
Enable all features
--no-default-features
Disable default features

ENVIRONMENT

BROWSER

Browser to use with --open

OUTPUT

Documentation generated in target/doc/<crate_name>/index.html

INSTALL

sudo apt install cargo
sudo dnf install cargo
sudo apk add cargo
sudo zypper install cargo
nix profile install nixpkgs#cargo

CAVEATS

Skips binaries with same name as library. Skips binaries with missing required features.

SEE ALSO

cargo(1), rustdoc(1)

RESOURCES

Source code · Documentation