TodayTools

Rust flashcards

Fast, safe systems code with no garbage collector.

Donate
Beginner friendly, starts from zero
Section
How to study
0
RustStart from zero · 1 of 12

What is Rust, in one plain sentence?

A programming language for writing fast, reliable programs that catches many mistakes before the program even runs.

Fast like a race car, with seat belts built in.

All topics

Rust at a glance

Rust is a programming language for fast, reliable programs that catches many mistakes before they ever run.

Like a strict but kind driving instructor who checks your mirrors and belts before you leave, so the drive itself is safe.

Words you will meet

Compiler
The translator that turns your code into a program and points out mistakes
Variable
A named box that holds a value
Type
The kind of thing a box holds, like a whole number or text
Function
A named set of steps that takes inputs and gives back a result
Heap
The big shelf of memory where growing things like text are kept
Ownership
Rust's rule that each value has exactly one owner who cleans it up
Borrow
Using a value without taking it from its owner, like borrowing a book
Cargo
Rust's helper that builds your project and adds packages

The steps

  1. 1. Start from zero (12 cards): What Rust is, why it exists and the words you need, in plain English.
  2. 2. Core basics (16 cards): Cargo, variables, numbers, expressions, strings, Vec and debugging.
  3. 3. Next steps (16 cards): Ownership, moves, borrowing, structs, enums, Option, Result, traits and iterators.
  4. 4. Go deeper (17 cards): Lifetimes, smart pointers, threads, Send and Sync, async, the 2024 edition and performance.
All 12 cards in Start from zero
What is Rust, in one plain sentence?
A programming language for writing fast, reliable programs that catches many mistakes before the program even runs.
What problem was Rust made to solve?
Fast languages like C and C++ let tiny memory mistakes crash programs or open security holes. Safer languages were often slower. Rust aims to give both speed and safety.
Where do you already meet Rust in daily life?
Inside the Firefox browser, parts of Windows and Android, the Linux system that runs most servers, and services like Discord and Cloudflare that carry a huge share of web traffic.
What is a good everyday picture of how Rust feels to use?
A strict but kind driving instructor who will not let you leave until the mirrors and belts are set. It is slower at first, but the drive itself is much safer.
What are code, a program and a compiler?
Code is instructions you write in a language like Rust. A program is code that runs. The compiler is a translator that turns your code into a program, and it also points out mistakes.
What are a variable, a value and a type?
A variable is a named box, and the value is what is inside it. The type says what kind of thing the box holds: a whole number (an integer), a decimal, text, or true or false.
What is a function?
A named set of steps that can take inputs and give back a result, like a recipe. In Rust it starts with fn, and every program begins in the function called main.
What is memory, and why must a program give it back?
Memory is the computer's short-term workspace. Small fixed things go on the stack, a fast pile; growing things go on the heap, a big shelf. Space not given back fills up and slows the computer.
What do ownership, borrowing and scope mean?
Each value has one owner. Borrowing lets other code read or use it without taking it, like lending a book. Scope is the block between { and } where a thing lives; at the end, it is cleaned up.
What do you need before you start, and what are the terminal, Cargo and a crate?
A computer and the free rustup installer, or just a browser with the official Rust Playground. The terminal is a window for typed commands. Cargo is Rust's helper for building, and a crate is a package of Rust code.
Your first tiny win: what does each line of this program do?
fn main() is the main function where every program starts. let name makes a variable holding text, and println! prints the line with the name filled in.
What will you be able to do after this topic?
Set up a Rust project, use variables, types, loops and functions, understand ownership and borrowing, handle errors calmly, and build fast command-line tools.
Rust cheatsheet

Cargo

  • cargo new app / cargo new --lib core New binary / library
  • cargo check Fast type and borrow check
  • cargo run --release -- --flag Optimised run with args
  • cargo test name -- --nocapture Filter tests, show prints
  • cargo clippy --all-targets -- -D warnings Strict lints
  • cargo fmt --check Formatting gate in CI
  • cargo add serde -F derive Add a dependency with a feature
  • cargo tree -d Find duplicate crate versions
  • cargo fix --edition Migrate to a new edition

Types and bindings

  • let x = 5; let mut y = 0; Immutable / mutable
  • const MAX: u32 = 10; Compile-time constant
  • i32 u8 u64 usize f64 bool char Common scalar types
  • let (a, b) = pair; Destructure a tuple
  • [0u8; 1024] Fixed array of 1024 zeros
  • x.checked_add(1) None on overflow
  • let v: u32 = s.parse()?; Parse text to a number
  • struct Id(u64); Newtype wrapper

Ownership and pointers

  • &T / &mut T Shared / exclusive borrow
  • x.clone() Explicit deep copy
  • Box<T> Owned heap value
  • Rc<T> / Arc<T> Shared owner: one thread / many
  • RefCell<T> / Mutex<T> Interior mutability: thread-local / shared
  • Weak<T> Non-owning link, breaks cycles
  • Cow<'a, str> Borrow, or own only when needed
  • std::mem::take(&mut v) Move out, leave default

Errors

  • Option<T>: Some / None Maybe a value
  • Result<T, E>: Ok / Err Success or failure
  • value? Unwrap or return early
  • opt.ok_or(Err::Missing)? Option to Result
  • res.map_err(AppError::from)? Convert the error type
  • unwrap_or / unwrap_or_else / unwrap_or_default Fallbacks
  • let Some(x) = opt else { return }; Bind or bail
  • anyhow .context("msg") Add context in apps

Iterators

  • .iter() / .iter_mut() / .into_iter() Borrow / mutate / take items
  • .filter(|x| ..).map(|x| ..) Lazy pipeline
  • .collect::<Vec<_>>() Gather into a collection
  • .sum::<u64>() / .count() Consumers
  • .enumerate() / .zip(other) Index / pair up
  • .find(|x| ..) / .any(..) / .all(..) Search and test
  • .chunks(100) / .windows(2) Slices of a slice
  • .fold(0, |acc, x| acc + x) Custom reduce
Donate