DEV Community

Kaito Ii
Kaito Ii

Posted on

Command to easily maintain rust dependencies with command line

Cargo edit

Cargo edit extends cargo by adding the following subcommands.
As you can guess by their names, the subcommands modify Cargo.toml from the command line.

  • cargo add
  • cargo rm
  • cargo upgrade

Install

$ cargo install cargo-edit

cargo add

$ cargo add image
Updating 'https://github.com/rust-lang/crates.io-index' index
Adding image v0.23.14 to dependencies

$ cat Cargo.toml                                                                                                          [dependencies]
image = "0.23.14"

Enter fullscreen mode Exit fullscreen mode

Add dependencies with a specific version.

$ cargo add image --vers=0.20                                                                                                  Updating 'https://github.com/rust-lang/crates.io-index' index
      Adding image v0.20 to dependencies

 ii@ii-pro  ~/t/r/image   master ⁝ ?
 $ cat Cargo.toml                                                                                                           [dependencies]
image = "0.20"
Enter fullscreen mode Exit fullscreen mode

cargo upgrade

$ cargo upgrade image                                                                                                      
    Updating 'https://github.com/rust-lang/crates.io-index' index
image:
    Upgrading image v0.20 -> v0.23.14
Enter fullscreen mode Exit fullscreen mode

cargo rm

$ cargo rm image
Removing image from dependencies

$ cat Cargo.toml                                                                                                           
Enter fullscreen mode Exit fullscreen mode

Top comments (0)