Rust and Cargo 1 cheatsheet

Rust and Cargo 1: Dependencies

8 common Rust and Cargo 1 tasks.

Add a dependency

Add a crate to Cargo.toml, here serde with its derive macros.

cargo add serde --features derive

Add a development dependency

Add a crate used only for tests and examples.

cargo add --dev pretty_assertions

Remove a dependency

Remove a crate from Cargo.toml.

cargo remove serde

Update dependencies

Update Cargo.lock to the newest versions Cargo.toml allows.

cargo update

Show the dependency tree

Print the dependencies as a tree.

cargo tree

Find duplicate crate versions

List crates that appear in more than one version.

cargo tree --duplicates

Install a command-line tool

Build and install a crate's binary into ~/.cargo/bin.

cargo install ripgrep

Check for vulnerable dependencies

Check Cargo.lock against the RustSec advisory database. Needs cargo-audit installed.

cargo install cargo-audit && cargo audit

Was this page helpful?