简体   繁体   English

如何使用 Cargo 下载 crate 的文档?

[英]How to download the documentation of a crate with Cargo?

In Haskell's Cabal, one can download the documentation for a package.在 Haskell 的 Cabal 中,可以下载软件包的文档。 Is it possible with Rust's Cargo? Rust 的货物可以吗? I searched on the Internet but found nothing.我在互联网上搜索,但一无所获。

You can build the documentation for all crates that are currently specified in your Cargo.toml by using the command您可以使用以下命令为当前在Cargo.toml 中指定的所有 crate 构建文档

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 命令列表可以通过cargo --help找到,命令的详细信息可以通过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.对我来说特别有用的是--open标志,它可以在浏览器中打开生成的文档。

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.您可以随时创建一个新的 Cargo 项目,添加所需的 crate 作为依赖项,然后按照上述步骤操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM