问题
In Haskell's Cabal, one can download the documentation for a package. Is it possible with Rust's Cargo? I searched on the Internet but found nothing.
回答1:
You can build the documentation for all crates that are currently specified in your Cargo.toml by using the command
cargo doc
A list of common Cargo commands can be found with cargo --help
, and detailed information for a command can be found with cargo COMMAND --help
:
$ cargo doc --help
cargo-doc
Build a package's documentation
USAGE:
cargo doc [OPTIONS]
OPTIONS:
-q, --quiet No output printed to stdout
--open Opens the docs in a browser after the operation
-p, --package <SPEC>... Package to document
--all Document all packages in the workspace
--exclude <SPEC>... Exclude packages from the build
--no-deps Don't build documentation for dependencies
--document-private-items Document private items
-j, --jobs <N> Number of parallel jobs, defaults to # of CPUs
--lib Document only this package's library
--bin <NAME>... Document only the specified binary
--bins Document all binaries
--release Build artifacts in release mode, with optimizations
--features <FEATURES> Space-separated list of features to activate
--all-features Activate all available features
--no-default-features Do not activate the `default` feature
--target <TRIPLE> Build for the target triple
--target-dir <DIRECTORY> Directory for all generated artifacts
--manifest-path <PATH> Path to Cargo.toml
--message-format <FMT> Error format [default: human] [possible values: human, json, short]
-v, --verbose Use verbose output (-vv very verbose/build.rs output)
--color <WHEN> Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
--offline Run without accessing the network
-Z <FLAG>... Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details
-h, --help Prints help information
By default the documentation for the local package and all dependencies is
built. The output is all placed in `target/doc` in rustdoc's usual format.
All packages in the workspace are documented if the `--all` flag is supplied. The
`--all` flag is automatically assumed for a virtual manifest.
Note that `--exclude` has to be specified in conjunction with the `--all` flag.
If the `--package` argument is given, then SPEC is a package ID specification
which indicates which package should be documented. If it is not given, then the
current package is documented. For more information on SPEC and its format, see
the `cargo help pkgid` command.
Especially useful to me is the --open
flag, which opens the generated documentation in a browser.
I do not believe that there is any way to generate the documentation for an arbitrary package that you are not using. You could always create a new Cargo project, add the desired crates as dependencies, then follow the above steps.
来源:https://stackoverflow.com/questions/35821185/how-to-download-the-documentation-of-a-crate-with-cargo