thecodex.expert · The Codex Family of Knowledge
Track 2 — Practitioner

Rust: Practitioner

Five lessons: traits, generics, closures, error handling, and collections.

🕐 ~5 hours5 lessonsRust 2024 edition

Lessons

Lesson 1

Traits and trait bounds

Defining traits, implementing traits, default methods, impl Trait parameters, and dyn Trait objects.

Prerequisite: Foundations track complete

What to look for:

  • impl Animal for Dog — concrete implementation
  • trait default methods — can be overridden
  • impl Trait vs T: Trait — same thing, cleaner syntax
  • dyn Trait — fat pointer, runtime dispatch, heap allocation needed
🕑 60 min
Lesson 2

Generics and standard library traits

Generic functions and structs, T: Trait bounds, derive macros, Display, Clone, Iterator.

Prerequisite: Lesson 1 of Practitioner

What to look for:

  • The standard traits table — Debug, Clone, PartialEq, Hash
  • #[derive] generates these automatically
  • Monomorphisation: zero-cost, each type gets its own compiled code
  • impl Display for custom types
🕑 50 min
Lesson 3

Closures and iterators

Closure syntax, capturing environment, Fn/FnMut/FnOnce traits, iterator adapters, and collect.

Prerequisite: Lesson 2 of Practitioner

What to look for:

  • |x| x * 2 closure syntax
  • Closures capture by reference by default, or by value with move
  • Iterator: map, filter, take, zip, flatten, collect
  • iter() vs into_iter() vs iter_mut()
🕑 50 min
Lesson 4

Error handling and the ? operator

Custom error types with From conversions, thiserror crate pattern, and anyhow for application code.

Prerequisite: Lesson 3 of Practitioner

What to look for:

  • From for AppError enables ? to auto-convert
  • map_err() to convert error types inline
  • Exploring tab: the full custom error type pattern
  • When to use Box (quick scripts) vs custom enums (libraries)
🕑 45 min
Lesson 5

Collections: Vec, HashMap, String

Vec operations, HashMap with entry API, String vs &str, and common collection patterns.

Prerequisite: Lesson 4 of Practitioner

What to look for:

  • vec![1,2,3] macro
  • HashMap::entry().or_insert() — idiomatic insert-or-update
  • String::from() vs to_string() vs &str
  • Iterating: for s in &v vs for s in v (consumes v)
🕑 40 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.

What is the difference between impl Trait and dyn Trait in function parameters?

What does #[derive(Debug)] do?

What does iterator.collect::>() do?

In Rust, what does map_err() do on a Result?

← Foundations trackAdvanced track →