Rust, Software Development

Show Rust Dependencies Using Cargo

It is now possible to show Rust dependencies using Cargo. Before Rust 1.44.0, there was not a built-in method to display a dependency graph. There was a plugin, though, called cargo-tree.

Show Rust Dependencies Using Cargo-tree

With the cargo-tree plugin, we need to install it as follows.

Once we installed it, run the command cargo tree.

Let us say we have this Cargo.toml file.

The plugin outputs the following.

To remove the cargo-tree plugin, run the following command.

The command generates the following output.

Now Cargo Built-In Command

Cargo-tree is now a Cargo build-in command starting with Rust 1.44.0. As such, all we need to do is update our Rust using the rustup update command. Alternatively, we could just install Rust 1.44.0 or later for new environments.

To ensure we are using the built-in command instead of the plugin, uninstall the cargo-tree plugin.

The same command works to show dependencies in Rust.

Although the same command works, some option flags are now different from that of the cargo-tree plugin. For example, --all-targets  to now --no-filter-targets.

Some other option flags remain the same such as the -p or --package, which lists all dependencies of a crate. Let us say we have this updated Cargo.toml.

To list all dependencies of actix-rt, we use the following command.

To view the list of options flags, use the following command.


Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.

You Might Also Like