Rust Programming
Core Rust concepts: ownership, the borrow checker, traits, error handling, and zero-cost abstractions.
- ownership /ˈəʊnəʃɪp/
Each value has exactly one owner; when the owner goes out of scope, the value is dropped and memory is freed automatically.
"Rust's ownership model caught our use-after-free bug at compile time — the value had been moved into another function and was no longer accessible."
- borrow checker /ˈbɒrəʊ ˌtʃekər/
Rust compiler component that enforces ownership and lifetime rules at compile time, guaranteeing memory safety without a garbage collector.
"The borrow checker rejected our code because we were holding a mutable reference while an immutable reference to the same data was still live."
- lifetime /ˈlaɪftaɪm/
Annotation (e.g. 'a) that tells the compiler how long a reference is valid; ensures no dangling pointers exist at runtime.
"We had to annotate the struct with a lifetime parameter because it held a reference to a string slice — the struct cannot outlive the data it borrows."
- move semantics /muːv sɪˈmæntɪks/
Transferring ownership of a value to a new binding; the original binding becomes invalid and cannot be used again.
"Passing the Vec to the function moved ownership into it — the caller can no longer use the Vec after the call unless the function returns it."
- trait /treɪt/
Rust's interface equivalent; defines shared behaviour across types. Types implement traits, and generic code can require trait bounds.
"We defined a Serialize trait and implemented it for each model so the HTTP handler can serialise any of them to JSON without knowing their concrete type."
- impl block /ɪmpl blɒk/
Implementation block that defines methods on a struct or implements a trait for a type.
"The impl Display for Error block lets us print our custom error type with {} in format strings."
- enum Result /ɪˈnjuːm rɪˈzʌlt/
Rust's primary error-handling type: Ok(value) represents success and Err(error) represents failure; must be explicitly handled.
"We use the ? operator to propagate Result errors up the call stack, keeping the happy path readable without nested match expressions."
- enum Option /ɪˈnjuːm ˈɒpʃən/
Rust's null-safety type: Some(value) means a value is present; None means it is absent. Eliminates null pointer dereferences.
"The map.get() returns Option<&V> — we pattern-match on it rather than risk a null dereference that would be a runtime crash in other languages."
- pattern matching /ˈpætən ˈmætʃɪŋ/
A match expression that exhaustively handles all variants of an enum or structure; the compiler ensures no case is missed.
"Our match on the HTTP status enum is exhaustive — adding a new variant causes a compile error until every match arm is updated."
- cargo /ˈkɑːɡəʊ/
Rust's package manager and build system; manages dependencies in Cargo.toml, compiles code, and runs tests with cargo test.
"We ran cargo add tokio --features full to add the async runtime dependency and cargo test to verify nothing broke."
- crate /kreɪt/
Rust's compilation unit; a package can contain a library crate and multiple binary crates.
"We published our validation logic as a separate crate on crates.io so both the CLI and the web server can depend on it."
- unsafe /ʌnˈseɪf/
Block that opts out of Rust's memory safety guarantees; required for FFI calls, raw pointer arithmetic, and mutable statics.
"The unsafe block calls a C library function — we wrapped it in a safe Rust API so callers never touch raw pointers."
- zero-cost abstraction /ˈzɪərəʊ kɒst æbˈstrækʃən/
Rust idiom: high-level abstractions such as iterators and generics compile to code as efficient as hand-written low-level code; no runtime overhead.
"Using an iterator chain with map and filter compiles to the same assembly as a hand-written loop — zero-cost abstraction in action."
- Arc/Mutex /ɑːk ˈmjuːteks/
Arc = thread-safe reference counting pointer; Mutex = mutual exclusion lock. Used together (Arc<Mutex<T>>) for shared mutable state across threads.
"We wrapped the connection pool in Arc<Mutex<Pool>> so multiple Tokio tasks can acquire a connection safely."
- derive macro /dɪˈraɪv ˈmækrəʊ/
Attribute like #[derive(Debug, Clone, PartialEq)] that auto-implements common traits without boilerplate code.
"Adding #[derive(Serialize, Deserialize)] to our structs lets serde handle JSON encoding automatically."
Quick Quiz — Rust Programming
Test yourself on these 15 terms. You'll answer 10 multiple-choice questions — each shows a term, you pick the correct definition.
What does this term mean?