Rust cheat sheet

A scannable Rust reference: 7 short snippets across 4 topics, each linking back to the lesson it came from.

At a glance

TopicWhat it covers
Error handling with Result and CargoDo not convert every error into a string too early. Erasing the type discards the ability to match on the cause, solesson
Setting up Rust: rustup, Cargo and edition 2024Rust is installed through rustup, a version manager rather than a package. It installs the toolchain — rustc, cargolesson
Modules, crates and project structuremod, pub and use, library versus binary targets, file and folder layout, workspaces, feature flags, dependency semverlesson
Testing, documentation and CIUnit tests in-module, integration tests, test organisation and fixtures, doc-tests, benchmarks, and a CI pipeline thatlesson

Quick snippets

Error handling with Result and Cargo

Cargo: layout, builds and dependencies

cargo new hello --bin      # binary crate; --lib for a library
cd hello

cargo build                # debug build into target/debug
cargo run                  # build and execute
cargo test                 # unit tests in #[cfg(test)] modules
cargo build --release      # optimised, target/release
cargo add serde --features derive
cargo clippy               # lint pass with many useful correctness lints
cargo fmt                  # apply rustfmt

Cargo: layout, builds and dependencies

[package]
name = "hello"
version = "0.1.0"
edition = "2021"

[dependencies]
serde = { version = "1", features = ["derive"] }
anyhow = "1"

[profile.release]
lto = true

Full lesson: Error handling with Result and Cargo →

Setting up Rust: rustup, Cargo and edition 2024

rustup and toolchains

rustup show                       # installed toolchains and the active one
rustup update                     # upgrade every channel
rustup toolchain install nightly  # opt in to a channel per project
rustup component add clippy rustfmt
rustup target add x86_64-unknown-linux-musl

rustup override set 1.85.0        # pin this directory to a version
rustc --version && cargo --version

rustup and toolchains

[toolchain]
channel = "1.85.0"
components = ["rustfmt", "clippy"]
targets = ["x86_64-unknown-linux-musl"]

Cargo.toml: the manifest

cargo new notes --bin      # binary crate; --lib for a library
cargo new --lib notes-core
cargo add clap --features derive
cargo add --dev tempfile
cargo add [email protected]

Full lesson: Setting up Rust: rustup, Cargo and edition 2024 →

Modules, crates and project structure

Layout: lib, bin and folders

[features]
default = ["memory"]
memory = []
sqlite = ["dep:rusqlite"]
full = ["sqlite", "metrics"]

[dependencies]
rusqlite = { version = "0.32", optional = true }

Full lesson: Modules, crates and project structure →

Testing, documentation and CI

Doc-tests and benchmarks

cargo test                        # unit + integration + doc-tests
cargo test --doc                  # doc-tests only
cargo test -- --nocapture         # show stdout from tests
cargo test -- --ignored           # run the slow ones
cargo bench                       # criterion, with statistical comparison
cargo test --release              # catch debug/release behaviour differences

Full lesson: Testing, documentation and CI →

FAQ

Is this Rust cheat sheet free to use?
Yes. No sign-up and no tracking: the page is static, every example is on the page itself, and you can print it or save it as a one-page reference.
Where do the examples come from?
Every snippet is taken from the 4 lessons of the Rust course on this site, and each section links back to the lesson it was pulled from.
How do I go deeper than a cheat sheet?
Open the full Rust course — it carries the worked explanations, the edge cases and the exercises behind every line here.

Node.js PHP Java HTTP Go Spring Boot

Last refreshed 2026-09-27.