Python Enums & the Option<T> Type (No Null!)
Rust enums are algebraic data types that can carry distinct data in each variant. Rust has no null reference; instead, the standard library provides Option<T> with variants Some(T) and None to represent presence or absence safely.
"In other languages, null is like a hidden landmine in a field of flowers. In Rust, Option<T> is a sealed gift box: it is either clearly labeled Some(gift) or None (empty box), and the compiler forces you to inspect the label before opening it."
Deep Dive: How It Works
Data-Bearing Enums: enum WebEvent { Click { x: i64, y: i64 }, KeyPress(char) }
The Option<T> Enum: enum Option<T> { Some(T), None }. Included automatically in standard prelude.
Forced Safety: You cannot access inner value T without explicitly handling the None variant.
Syntax Blueprint
match maybe_value { Some(v) => println!("{}", v), None => println!("Empty") }Forces complete handling of missing data at compile time, eliminating null pointer exceptions.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Calling .unwrap() on a None value.Why it happens: unwrap() extracts Some(v) but panics at runtime if the value is None.
How to fix: Use match, if let, or .unwrap_or(default) for safe fallbacks.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Unpack Option with match
Write fn find_user(id: i32) -> Option<&'static str> that returns Some("Alex") if id == 1 else None.
In main(), match find_user(1) and print "Found User: Alex".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.