Rust Toolchain Cheat Sheet

In progress

The three tools I use with Rust and the commands I reach for.

Overview

Tool Role
rustup installs and updates Rust toolchains (stable, beta, nightly)
rustc the compiler; Cargo calls it for you
cargo package manager and build tool; packages are crates, published on crates.io

Details

rustup

rustup --version
rustup update                          # update the installed toolchains
rustup toolchain list
rustup toolchain install nightly

Project Lifecycle with cargo

cargo new my-project        # src/main.rs, Cargo.toml, a Git repo and .gitignore
cargo build                 # debug build in target/debug
cargo run                   # build and run (debug profile: unoptimized, with debug info)
cargo run --release         # optimized build in target/release
cargo check                 # type-check without producing a binary (fast)
cargo test

Dependencies and Binaries

cargo add tokio                        # add a dependency to Cargo.toml
cargo add tokio --features full        # with a crate feature enabled
cargo install ripgrep                  # install a crate's binary system-wide (~/.cargo/bin)

References

Review cards

Quiz Which command would you use to install the nightly toolchain with rustup?
  • rustup toolchain install nightly
  • rustup install nightly
  • rustup update nightly
  • rustup toolchain install stable

The rustup toolchain install nightly command specifically installs the nightly toolchain.