← 返回命令列表

Linux command

cargo-tree 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Show dependency tree

cargo tree

Show inverted tree for package

cargo tree --invert [package]

Show duplicate dependencies

cargo tree --duplicates

Show features enabled by dependencies

cargo tree --edges features

Show without deduplication

cargo tree --no-dedupe

Show specific package subtree

cargo tree -p [package]

ASCII output

cargo tree --charset ascii

说明

cargo tree displays a tree visualization of the dependency graph for a Rust project. It shows all packages and their transitive dependencies in an indented tree format, with packages marked `(*)` indicating they have already been shown elsewhere and are deduplicated. The command supports several analysis modes: `--invert` traces which packages depend on a given crate, `--duplicates` shows packages that appear multiple times with different versions, and `--edges features` reveals how features propagate through the dependency graph. Built into Cargo since Rust 1.44, it replaced the earlier `cargo-tree` third-party plugin.

参数

-i, --invert _spec_
Invert tree, showing what depends on package
-p, --package _spec_
Package to use as tree root
-e, --edges _kinds_
Dependency types: normal, dev, build, features, all
-d, --duplicates
Show packages built multiple times
--no-dedupe
Don't deduplicate repeated packages
--depth _n_
Maximum display depth
--prune _spec_
Prune packages from display
--charset _set_
Character set: utf8, ascii
--format _fmt_
Format string for package display
--prefix _prefix_
Prefix: indent, depth, none
--target _triple_
Filter for target platform
--all-features
Enable all features
--features _features_
Enable specific features

FAQ

What is the cargo-tree command used for?

cargo tree displays a tree visualization of the dependency graph for a Rust project. It shows all packages and their transitive dependencies in an indented tree format, with packages marked `(*)` indicating they have already been shown elsewhere and are deduplicated. The command supports several analysis modes: `--invert` traces which packages depend on a given crate, `--duplicates` shows packages that appear multiple times with different versions, and `--edges features` reveals how features propagate through the dependency graph. Built into Cargo since Rust 1.44, it replaced the earlier `cargo-tree` third-party plugin.

How do I run a basic cargo-tree example?

Run `cargo tree` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -i, --invert _spec_ do in cargo-tree?

Invert tree, showing what depends on package