I expected there to be something like cargo install stopwatch
but could not find it in the docs.
I've been finding the package version and manually adding it to Cargo.toml:
[dependencies]
stopwatch = "0.0.6"
But this is tedious and I feel it should be more automated.
As of Rust 1.62.0, there is a built-in add
sub-command to add dependencies and avoid having to edit the Cargo.toml file yourself.
To add the latest version:
cargo add stopwatch
To add a specific version:
cargo add [email protected]
More details in the Cargo book.
No, there is no such thing built in to Cargo. There is only a cargo install
subcommand which installs the binaries of a crate system-wide.
New third-party Cargo subcommands can be created, and cargo edit, does what you want.
These cargo subcommands can then be installed by cargo install
, in a fun meta circle!
% cargo install cargo-edit
# Now `cargo add` is available
% cargo add mycrate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With