Traits, Generics & Dispatch
How Rust reuses code without inheritance. Bounds, associated types, blanket impls, and the real cost difference between a generic and a dyn Trait.
// lessons
- 01
Defining & Implementing a Trait
Write a trait with a default method and override it.
- 02
Trait Bounds & where Clauses
Constrain a generic so the body compiles, without over-constraining it.
- 03
Associated Types vs Generic Parameters
Choose correctly between them, and say why Iterator uses one and not the other.
- 04
Static Dispatch & Monomorphization
Explain what the compiler emits for a generic function, and what it costs.
- 05
Trait Objects & the Vtable
Store mixed types behind Box<dyn Trait> and name the runtime cost.
- 06
Object Safety
Predict which traits can become trait objects before the compiler tells you.
- 07
Blanket Impls & the Orphan Rule
Implement a trait for every type that satisfies a bound — and know when you may not.
Every exercise compiles and runs in the Forge sandbox — standard library only, no external crates.
