RUST SERIES · 22 lessons

From basics to async — Rust in 22 lessons.

A step-by-step 22-lesson track: basics → ownership → type system → error handling → modern Rust. Every lesson bundles a README, runnable example code (`src/*.rs`), a homework spec, and the answer code. Designed so first-time systems-language learners can internalize Rust's own thinking — ownership, the borrow checker, traits — and the later lessons cover async/await with tokio so you can read and write real-world service code.

View source repository ↗
🦀

Basics

5 lessons · install · variables · types · control flow · functions

🦀
#01

01. Getting Started with Rust (rustup · cargo · hello world)

Basics · Prerequisite: none

Rust is a systems programming language that guarantees memory safety at compile time. Without a garbage collector it delivers C/C++ class performance while preventing data races, null-pointer bugs, and use-after-free at the type-check phase. In this lesson you install the toolchain with rustup and run your first project with cargo.

🦀
#02

02. Variables, Constants, Shadowing, Type Inference

Basics · Prerequisite: lesson 01

Rust variables are immutable by default. You add `mut` to make them mutable. This design improves multi-thread safety and code readability at the same time, and shadowing lets you reuse names without `mut`. This lesson also covers the difference between `let` and `const`, and when to annotate types vs. trust inference.

🦀
#03

03. Basic Types (Integer, Float, bool, char, tuple, array)

Basics · Prerequisite: lesson 02

Rust's scalar types (i8/u8/i32/i64/f32/f64/bool/char) and compound types (tuple/array) — all in one lesson. The differences from other languages: integer overflow handling, char being a 4-byte Unicode scalar, and arrays having compile-time fixed size. (Heap-allocated dynamic vectors come in the next lesson cluster.)

🦀
#04

04. Control Flow (if · loop · while · for · break-with-value)

Basics · Prerequisite: lesson 03

Rust's `if` is an expression — you can write `let x = if cond { 1 } else { 2 }`. This lesson covers `loop` / `while` / `for`, Rust-specific touches like attaching a value to `break`, labeled break / continue across nested loops, and `for` over ranges and iterators.

🦀
#05

05. Functions, Expressions, Return Values, Doc Comments

Basics · Prerequisite: lesson 04

Defining functions with `fn name(arg: T) -> R { ... }`, the distinction between expressions and statements, returning implicitly via the last expression vs. explicit `return`, and `///` doc comments that turn into HTML via `cargo doc`. This lesson sets you up to write idiomatic functional Rust.

🔒

Ownership

5 lessons · ownership · borrowing · slices · lifetimes · String

🦀
#06

06. The Three Rules of Ownership + move/copy

Ownership · Prerequisite: lessons 1-5

Ownership is the mechanism by which Rust guarantees memory safety without a garbage collector. Three rules suffice — each value has exactly one owner, the value is dropped when its owner goes out of scope, and assignment / argument passing moves ownership. This lesson covers move vs. copy, the meaning of Drop, and leads naturally into borrowing.

🦀
#07

07. References and Borrowing (&T, &mut T, the borrow rules)

Ownership · Prerequisite: lesson 06

Borrowing lets you use a value without taking ownership — `&` for an immutable reference, `&mut` for a mutable one. The core rule is that at any moment you have either (N shared references) OR (1 exclusive mutable reference), never mixed. This is what blocks data races at compile time.

🦀
#08

08. Slices — &str and &[T]

Ownership · Prerequisite: lesson 07

A slice is a reference view into part of a collection. `&str` is a view into a String or into a static string literal; `&[T]` is a view into a Vec or array. Slices supercharge function signatures and explain why `&str` is the idiomatic argument type rather than `String`.

🦀
#09

09. Lifetimes — explicit 'a and elision rules

Ownership · Prerequisite: lesson 08

A lifetime is a compile-time marker for how long a reference is valid. You write them as `'a`, but most of the time the compiler infers them through elision rules. This lesson covers why lifetimes exist, when to write them by hand, and the meaning of `'static`.

🦀
#10

10. String and &str in Depth — UTF-8, indexing

Ownership · Prerequisite: lesson 09

Rust strings are UTF-8 encoded. `String` is a heap-owned mutable buffer, `&str` is a reference view into part of it. This lesson explains why integer indexing is intentionally disallowed and how `.chars()` / `.bytes()` / `.char_indices()` give you explicit control over Unicode iteration.

🧱

Type system

4 lessons · struct · enum · pattern matching · traits

⚠️

Error handling

4 lessons · Result/Option · ? operator · panic · thiserror

Modern Rust

4 lessons · modules/Cargo · testing · concurrency · async