cargo-doc
Build and view Rust crate documentation
TLDR
Build the documentation for the current project and all dependencies
Do not build documentation for dependencies
Build and open the documentation in a browser
Build and view the documentation of a particular package
SYNOPSIS
cargo doc [options]
PARAMETERS
--open
Opens the generated documentation in a web browser after building.
--no-deps
Only builds documentation for the current package, not its dependencies.
--document-private-items
Includes documentation for private items in the generated documentation. By default, only public items are included.
--package <SPEC>
Builds documentation for only one specified package. SPEC is a package ID specification.
--workspace
Build all packages in the workspace.
--all-features
Activate all available features.
--features <FEATURES>
Space-separated list of features to activate.
--no-default-features
Do not activate the `default` feature.
--target <TARGET>
Build for the target triple. The default is the host platform.
--manifest-path <PATH>
Path to the Cargo.toml file. Defaults to the current directory.
-j <N>, --jobs <N>
Number of parallel jobs to use. Defaults to the number of CPUs.
--out-dir <PATH>
The target directory for all generated artifacts (default: target/doc)
--offline
Run without accessing the network.
-v, --verbose
Use verbose output.
-q, --quiet
Do not print cargo log messages.
DESCRIPTION
The cargo doc command builds documentation for the current package and all of its dependencies.
It generates HTML documentation from the Rust source code, using the `rustdoc` tool, and then opens the documentation in a web browser. This is useful for browsing the API of your project, as well as all crates depended upon.
The documentation includes both API documentation, derived from comments marked with `///` or `//!`, and module-level documentation using doc attributes. It's a powerful tool for navigating and understanding Rust projects. Cargo manages compiling and handling all dependencies, allowing `rustdoc` to create complete, linked documentation. The output is saved in the `target/doc` directory by default.
DOC ATTRIBUTES
Use the following attributes for documenting:
///: Documentation comment for the item after the comment.
//!: Documentation comment for the enclosing module.
#[doc = "..."]: Attribute form for documentation comments, useful for more complex scenarios.
FEATURE FLAGS
Feature flags are used to conditionally compile parts of your crate. When generating documentation, feature flags can be specified to conditionally include/exclude parts of the documented API. This can be helpful for documenting optional functionalities.
SEE ALSO
cargo(1), cargo-build(1)