Language basics
39 steps in 8 sets of Rust.
Rust before the hard parts. Variables, the type system, compound values, control flow, functions, text, and the collections you will use most. Pattern matching gets its own set because match is not a switch statement and treating it like one wastes the best thing in the language.
Thirty-nine steps, and none of it fights you yet. Ownership is the next tour, and it will.
Variables & types
- Variables and mutabilityBindings are immutable by default; mut opts in.
- Shadowing and constantsReusing a name with
let, and compile-time constants. - Scalar types and castsRust's sized integers, floats, bools, and chars.
- Integer overflowRust will not let an overflow slide: pick the behavior you want explicitly.
- Floats and castsFloating point maths, and the explicit casts Rust demands between types.
- Characters and bytesA char is a Unicode scalar; bytes are something else, and Rust keeps them apart.
Compound values
- TuplesFixed-size groups of mixed types.
- ArraysFixed-size arrays live on the stack and carry their length in the type.
- Tuple and unit structsStructs without field names: newtypes for meaning, unit structs for markers.
- DestructuringPatterns pull structs, tuples and nested values apart in one binding.
Control flow
- if / else if / elseBranching where every branch is an expression.
- LoopsRust's three loop forms: for, while, and loop.
- RangesRanges are values: iterate them, reverse them, step through them.
- Loops that return valuesloop is an expression: break carries a value out, and labels pick which loop to leave.
- while letwhile let keeps looping as long as the pattern matches — draining a stack, say.
- let elselet else binds on the happy path and forces the failure branch to diverge.
- Everything is an expressionBlocks, ifs and matches all evaluate to a value, which is why Rust needs few statements.
- FizzBuzzThe classic screening exercise, written with match rather than if.
Pattern matching
- match expressionsExhaustive pattern matching over a value.
- Enum with matchAn enum with data in its variants, matched exhaustively.
- Match guards and bindingsA guard adds a condition to an arm; @ keeps the value you matched on.
- Slice patternsMatching on the shape of a slice: empty, one element, first and last, the middle.
Functions
- FunctionsDefining, composing, and passing functions.
- GCDEuclid's algorithm, still the shortest correct answer after two thousand years.
- Iterative FibonacciFibonacci without recursion, and a first look at shadowing.
- Constants and type aliasesCompile-time constants, program-lifetime statics, and names for long types.
Text
- Format stringsThe formatting mini-language: width, precision, alignment, debug output.
- Parsing textTurning strings into numbers, and deciding what a failure means.
- Building stringsGrowing a String, joining pieces, and the cheap ways to slice text.
Collections
- VectorsThe growable Vec and its everyday methods.
- Working a VecThe Vec methods that do real work: filtering in place, sorting by key, windows.
- Sorting and searchingSorting by a comparator, finding extremes, and searching a sorted slice.
- Binary searchHalve the range each step, with the index arithmetic the borrow checker is happy about.
- The entry APIOne lookup instead of two: entry gives you the slot, occupied or not.
- HashSetMembership and set algebra, with no duplicate values by construction.
- BTreeMapAn ordered map: iteration follows the keys, and you can ask for a range.
- VecDequeA ring buffer: push and pop at either end in constant time.