reference · rust fluency

cargo cheatsheet

daily commands

commandwhat it does
cargo new namescaffold a new binary project
cargo runcompile and run (debug build)
cargo checkfast compile analysis, no binary. use while iterating
cargo buildcompile to target/debug/
cargo build --releaseoptimized compile to target/release/
cargo testrun all tests
cargo add dep_nameadd a dependency to Cargo.toml
cargo fmtformat code (rustfmt)
cargo clippylinter. catches idiomatic mistakes
cargo doc --openbuild and open docs for your crate and deps

project layout

myproject/
├── Cargo.toml        # manifest: metadata + dependencies
├── Cargo.lock        # pinned dep versions. commit it for binaries
└── src/
    ├── main.rs       # binary entry point (fn main)
    └── lib.rs        # library entry point, if the crate is a library

a crate can be a binary, a library, or both. one package may contain multiple crates.

Cargo.toml essentials

[package]
name = "myproject"
version = "0.1.0"
edition = "2024"

[dependencies]
serde = "1.0"          # semver-compatible: >=1.0.0, <2.0.0

edition is the language edition, not your version. 2021 and 2024 are the ones you will see in the wild.

mental model

source: the cargo book and the rust book ch 1.3.