cargo Verified current stable Not installed? Programming

Cargo / Build And View Documentation For Package

Build And View Documentation For Package

Builds and opens documentation for a specified package within a workspace.

$
Terminal
cargo d --open -p <package>

When To Use

When working in a multi-package workspace and needing the documentation of a specific package for localized review or testing.

Pro Tip

Use `--features` to enable features in the documentation which may alter the output significantly based on optional functionality.

Command Builder

Tune the command before you copy it

Back to syntax
$
Generated Command
cargo d --open -p <package>

Terminal Output

Expected runtime feedback

Simulated preview
>
Output
Finished dev [unoptimized + debuginfo] target(s) in 0.12s
    Opening documentation for `example_package` in your browser...

Anatomy of Output

Understanding the result

Documenting `my_package` v0.1.0 (path/to/my_package) INFO

Shows that the documentation for `my_package` is being built.

Opening documentation at http://localhost:8000/doc/my_package/index.html INFO

Indicates the URL where the built documentation can be accessed.

Finished dev [unoptimized + debuginfo] target(s) in 0.98s BUILD STATUS

Completion time for the documentation build.

Power User Variants

Optimized versions

cargo doc --open --package my_package --no-deps

Open documentation for a package without dependencies.

cargo doc --open --package my_package --all-features

Open documentation for a package with all features enabled.

Troubleshooting

Common pitfalls

error: Package `my_package` not found

Solution: Verify the package name and ensure it exists in the workspace.

error: Failed to open documentation at specified URL

Solution: Check for running process or server that serves the documentation.

warning: no targets were compiled, documentation will be incomplete

Solution: Ensure at least one target within the package is built.

Command Breakdown

What each part is doing

cargo
Base Command
The executable that performs this operation. Here it runs Cargo before the shell applies any redirect operators.
d
d|doc
The value supplied for d|doc.
-p
p| package
The value supplied for p| package.
<package>
package
The value supplied for package.
--open
Command Option
Tool-specific option used by this command invocation.
-p
Command Option
Tool-specific option used by this command invocation.

How To Run

Execution path

  1. Step 1

    Run `cargo doc --open -p example_package` to build and view documentation.

  2. Step 2

    Verify that the documentation opens in your default web browser.

Alternative Approaches

Comparable commands in other tools

Alternative programming tools for the same job.