Rust Cheat Sheet

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

A single-page, colour-coded summary of the Rust language, written against Rust 1.99.0 and the 2024 edition (checked 2026-10-06) — the rustup and cargo command map and a Cargo.toml skeleton with features, profiles, [lints] and a workspace, primitive types, literals and casts, let/mut/const/static and shadowing, control flow with loop values, labels, if let, let-else and let chains, the ownership and borrowing rules in one box with the lifetime elision rules, structs, enums and pattern syntax, Option/Result combinators and ? with an error-type recipe, collection, string and iterator one-liners, generics versus impl Trait versus dyn Trait, closures and the Fn traits, a smart-pointer and interior-mutability chooser, the Send/Sync table, threads, channels and async, modules and visibility, macro_rules! fragment specifiers, the unsafe superpowers, testing and tooling flags, and a strip of what changed since older tutorials — handy for quick memorization or as a downloadable PDF desk reference.

Download the Rust Cheat Sheet (PDF)

For the full explanation, every option, and additional examples, see the dedicated pages:

Start here — Rust Reference.

Worked example

The example parses two numbers with ?, handles the error case in match, and chains iterator adapters.

use std::num::ParseIntError;

fn total_pages(a: &str, b: &str) -> Result<u32, ParseIntError> {
    let x: u32 = a.trim().parse()?;
    let y: u32 = b.trim().parse()?;
    Ok(x + y)
}

fn main() {
    println!("{:?}", total_pages("120", " 80 "));
    match total_pages("120", "abc") {
        Ok(n) => println!("{n} pages"),
        Err(e) => println!("error: {e}"),
    }

    let titles = vec!["Dune", "Emma", "Ulysses"];
    let long: Vec<usize> = titles.iter().map(|t| t.len()).filter(|&n| n > 4).collect();
    println!("{long:?}");
}
Ok(200)
error: invalid digit found in string
[7]

Each ? returns the Err early, converting it with From; the iterator chain is lazy and runs only when collect() drives it.