Chapter 14: Option, Result, and Rust’s Error Philosophy
Prerequisites
You will understand
- Why Rust has no
null - The
?operator as early-return sugar - When to
unwrapvs propagate errors
Reading time
30 min
+ 20 min exercises
Builds on Chapter 13
Option<T> and Result<T, E> are enums. Pattern matching is how you extract the success or failure value — there is no null to check.
Revisit Ch 13 →
Null vs Type
Hidden Nullability vs Explicit Absence
Error Flow
What `?` Expands Into
Decision Flow
Choosing How to Handle a Result or Option
? first in production code — it keeps the happy path linear and makes errors the caller's problem. Use match when you need local recovery. Use .unwrap() only when you can prove the value is always present, or in tests.