March 17, 2022

Using cargo-edit to simplify dependency management

Getting back into Rust, I want to start documenting my journey to getting a small service running. The first "problem" I had to solve was to add dependencies to the project.

The official method is to add the dependencies manually in your Cargo.toml file. However, this is not convenient, and could lead to errors quite easily.

Thankfully, you can make this easier using cargo-edit. This will let you add, remove, upgrade dependencies or set-version of your crate.

To install cargo-edit, simply run

cargo install cargo-edit

Then, as I wanted to install axum, I simply ran

cargo add axum

To install a package with extra features, such as tokio with full features

cargo add tokio --features=full

Whenever I want to upgrade all packages, I can then

cargo upgrade

I can also update a single package

cargo upgrade axum

Do not mistake upgrade and update. The upgrade command will upgrade your dependencies to the latest version, while the update command is a cargo builtin that will update your Cargo.lock.

Copyright Marin Gilles 2019-2021