cargo-add

Add dependencies to a Rust project

TLDR

Add dependency
$ cargo add [serde]
Add with specific version
$ cargo add [[email protected]]
Add with features
$ cargo add [tokio] --features [full]
Add as dev dependency
$ cargo add [mockall] --dev
Add as build dependency
$ cargo add [cc] --build
Add from git repository
$ cargo add --git [https://github.com/user/repo]
Add from local path
$ cargo add --path [../my-crate]
Add as optional dependency
$ cargo add [feature-crate] --optional
Rename dependency
$ cargo add [serde] --rename [my_serde]

SYNOPSIS

cargo add [options] crate...cargo add [options] --path pathcargo add [options] --git url [crate...]

DESCRIPTION

cargo add adds or modifies dependencies in Cargo.toml. It fetches crate information from the registry and updates the manifest with the correct version constraints. Built into Cargo since v1.62.

PARAMETERS

--dev, -D

Add as development dependency
--build, -B
Add as build dependency
--optional
Mark dependency as optional
--rename name
Rename the dependency
--features features
Enable specific features
--no-default-features
Disable default features
--default-features
Re-enable default features
--path path
Add dependency from local path
--git url
Add dependency from git repository
--branch branch
Git branch to use
--tag tag
Git tag to use
--rev sha
Git commit to use
-p, --package spec
Package to modify
--dry-run
Show changes without modifying files

OUTPUT

Lists enabled (+) and disabled (-) features of added dependencies.

INSTALL

sudo pacman -S cargo-edit
sudo apk add cargo-edit
brew install cargo-edit
nix profile install nixpkgs#cargo-edit

CAVEATS

Updates existing entries with specified flags. For Cargo versions before 1.62, install cargo-edit for this functionality.

SEE ALSO

cargo(1), cargo-remove(1), cargo-update(1)

RESOURCES

Source code · Documentation