{{*set actionverb=“Add”}} {{*set nouns=“adds”}}
cargo-add - Add dependencies to a Cargo.toml manifest file
cargo add
[options] crate...cargo add
[options] --path
pathcargo add
[options] --git
url [crate...]\
This command can add or modify dependencies.
The source for the dependency can be specified with:
@
version: Fetch from a registry with a version constraint of “version”--path
path: Fetch from the specified path--git
url: Pull from a git repo at urlIf no source is specified, then a best effort will be made to select one, including:
dev-dependencies
)When you add a package that is already present, the existing entry will be updated with the flags specified.
{{#option “--git
url” }} Git URL to add the specified crate from. {{/option}}
{{#option “--branch
branch” }} Branch to use when adding from git. {{/option}}
{{#option “--tag
tag” }} Tag to use when adding from git. {{/option}}
{{#option “--rev
sha” }} Specific commit to use when adding from git. {{/option}}
{{#option “--path
path” }} Filesystem path to local crate to add. {{/option}}
{{> options-registry }}
{{/options}}
{{#option “--dev
” }} Add as a development dependency. {{/option}}
{{#option “--build
” }} Add as a build dependency. {{/option}}
{{#option “--target
target” }} Add as a dependency to the given target platform. {{/option}}
{{/options}}
{{#option “--rename
name” }} Rename the dependency. {{/option}}
{{#option “--optional
” }} Mark the dependency as optional. {{/option}}
{{#option “--no-optional
” }} Mark the dependency as required. {{/option}}
{{#option “--no-default-features
” }} Disable the default features. {{/option}}
{{#option “--default-features
” }} Re-enable the default features. {{/option}}
{{#option “--features
features” }} Space or comma separated list of features to activate. When adding multiple crates, the features for a specific crate may be enabled with package-name/feature-name
syntax. This flag may be specified multiple times, which enables all specified features. {{/option}}
{{/options}}
{} {{> options-display }} {{/options}}
{} {{> options-manifest-path }} {{/options}}
{{> section-options-common }}
{{> section-environment }}
{{> section-exit-status }}
Add regex
as a dependency
cargo add regex
Add trybuild
as a dev-dependency
cargo add --dev trybuild
Add an older version of nom
as a dependency
cargo add nom@5
Add support for serializing data structures to json with derive
s
cargo add serde serde_json -F serde/derive
{{man “cargo” 1}}