Topic
Option
Option is a built-in Rust enum that replaces null. Instead of letting a missing value crash your program, Option forces you to handle both possibilities: Some(value) when data exists, None when it doesn't. Every function that might not find what it's looking for returns Option, and match or if let makes it safe to unwrap.
Quick Reference
| Concept | What it means |
|---|---|
| Option | A built-in enum that replaces "null" in Rust. It says "this might have a value, or it might not." |
| Some(T) | One variant of Option that wraps an actual value. Some(5) means "there is a value, and it's 5." |
| None | The other variant of Option. None means "there is no value." |
| match on Option | The standard way to handle both possibilities - check for Some and None. |
| if let | A shorter way to unwrap Some when you only care about the value-carrying case. |
| Prelude | Rust's built-in types (like Option) that you can use without importing anything. |
| Term | What it means | When you use it |
|---|---|---|
| Option | A built-in enum that replaces null in Rust | When a value might or might not exist |
| Some(T) | The variant that wraps an actual value | When you have a value and want to signal it exists |
| None | The variant that means there is no value | When indicating the absence of a value |
| match on Option | The standard way to handle both Some and None cases | When you need to handle both the present and absent cases explicitly |
| if let | A shorter way to unwrap Some when you only care about the value case | When you only need to act if a value is present |
| Prelude | Rust built-in types available without any import statement | Option, String, Vec - always available, no use needed |