Forrest logo
back to the cargo tool

cargo-add:tldr:ca754

cargo-add: Add a specific version of a dependency.
$ cargo add ${dependency}@${version}
try on your machine

The cargo add command is used in the Rust programming language and its package manager, Cargo. It is typically used to add a dependency to the project's Cargo.toml file.

The ${dependency} part in the command should be replaced with the name of the dependency you want to add to your project. For example, if you want to add the serde dependency, you would replace ${dependency} with serde.

The ${version} part should be replaced with the desired version of the dependency you want to add. This allows you to specify a specific version or use version constraints. For example, if you want to add version 1.0.0 of serde, you would replace ${version} with 1.0.0.

So, when you run cargo add ${dependency}@${version}, Cargo will add the specified ${dependency} with the specified ${version} to your project's Cargo.toml file along with any other necessary changes, such as updating the Cargo.lock file and fetching the required dependencies.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the cargo tool