thecodex.expert · The Codex Family of Knowledge
Track 1 — Foundations

Rust: Foundations

Five lessons: ownership, borrowing, structs, enums, Option, and Result.

🕐 ~5 hours5 lessonsRust 2024 edition

Lessons

Lesson 1

Variables, types, and control flow

let, mut, basic types (i32, f64, bool, char), if/else, loop, while, for, and pattern matching basics.

What to look for:

  • Variables are immutable by default — use mut for mutability
  • Type inference: Rust knows the type from context
  • let x: i32 = 5 vs let x = 5 (inferred)
  • for i in 0..5 range syntax
🕑 40 min
Lesson 2

Ownership and move semantics

The three ownership rules, move vs copy, clone(), and when memory is freed.

Prerequisite: Lesson 1

What to look for:

  • The three ownership rules — memorise them
  • Move: String assignment transfers ownership
  • Copy: i32, f64, bool are copied silently
  • When drop() is called — end of scope
🕑 60 min
Lesson 3

Borrowing and references

& immutable references, &mut mutable references, the borrow rules, and slices.

Prerequisite: Lesson 2

What to look for:

  • Borrow rule: many & OR one &mut, never both
  • &str vs String — prefer &str in function parameters
  • Slices: &s[0..5] — reference to part of a collection
  • The borrow checker error messages are informative — read them fully
🕑 60 min
Lesson 4

Structs, enums, and impl

Struct definition, impl blocks with methods and associated functions, enums with data, and derive macros.

Prerequisite: Lesson 3

What to look for:

  • impl User { fn new(...) -> Self } — constructor pattern
  • #[derive(Debug)] — free debug printing
  • Enum variants can hold data — this is not a C enum
  • match must be exhaustive — all variants or _ wildcard
🕑 50 min
Lesson 5

Option and Result

Option as the null replacement, Result for recoverable errors, match, if let, and ? operator.

Prerequisite: Lesson 4

What to look for:

  • Option replaces null — Some(value) or None
  • Result replaces exceptions — Ok(value) or Err(error)
  • ? operator: propagate error up the call stack
  • unwrap() is a deliberate panic choice — not error handling
🕑 50 min

How to use this track: Each lesson links to the Codex Rust reference page. Use reading level tabs. Rust borrow checker errors are the lesson — read them carefully. Practice at play.rust-lang.org.

Track quiz

4 questions to check your understanding.

In Rust, what does let x = String::from("hello"); let y = x; do to x?

How many mutable references to the same data can exist at one time?

What does Option represent in Rust?

What does the ? operator do when applied to a Result?

Practitioner track →