Skip to content

Instantly share code, notes, and snippets.

@carloocchiena
Last active March 6, 2023 12:09
Show Gist options
  • Save carloocchiena/62adaafbfefb2d0ec17fa2d9dded459f to your computer and use it in GitHub Desktop.
Save carloocchiena/62adaafbfefb2d0ec17fa2d9dded459f to your computer and use it in GitHub Desktop.

Cargo CLI commands

Source: https://doc.rust-lang.org/cargo/commands/general-commands.html

bold = very useful

cargo --version (actual version)
cargon --list (list installed commands)
cargo --help (provide helps)
cargo --explain code (explain specific functions)
cargo bench (run benchmark of code and packages)
cargo build (compile current package)
cargo rustc (compile current package)
cargo run (compile and execute the current package)
cargo check (check current package)
cargo clean (remove cargo artifact made in various run)
cargo doc (build and create package’s documentation)
cargo doc --open (build, create and open package’s documentation)
cargo fetch (fetch dependencies from the network)
cargo fix (fix lint warnings automatically)
cargo test (execute unit and integration tests of a package)
cargo report type (generate various type of reports)
cargo tree (display a tree view of current env)
cargo update (update dependencies as per local lock file)
cargo init (create a new cargo package in an existing directory)
--bin (Create a package with a binary target (src/main.rs). This is the default behavior.)
--lib (Create a package with a library target (src/lib.rs).)
--edition edition (Specify the Rust edition to use. Default is 2021. Possible values: 2015, 2018, 2021)
--name name (Set the package name. Defaults to the directory name.)
cargo new (create a new cargo package and also create the named directory)
--bin (Create a package with a binary target (src/main.rs). This is the default behavior.)
--lib (Create a package with a library target (src/lib.rs).)
--edition edition (Specify the Rust edition to use. Default is 2021. Possible values: 2015, 2018, 2021)
--name name (Set the package name. Defaults to the directory name.)
cargo install (build and install rust binary locally from crates.io)
cargo uninstall (remove a rust binary)
cargo publish (publish current package to crates.io - Be careful, because a publish is permanent. The version can never be overwritten, and the code cannot be deleted. One major goal of crates.io is to act as a permanent archive of code so that builds of all projects that depend on crates from crates.io will continue to work. Allowing version deletions would make fulfilling that goal impossible. However, there is no limit to the number of crate versions you can publish. To get a better understanding of this, check: https://crates.io/search?q=guessing%20game)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment