Start with the idea
Pattern matching and the ? operator keep both cases explicit without null, sentinel values, or exceptions. Reach for Option when absence is normal and expected, and Result when the caller needs to know why something did not work.
Ask what the caller needs to know when there is no value. If a search simply finds nothing, Option<T> describes the two normal outcomes: Some(item) or None. If a parser fails, Result<T, E> describes success plus a reason for failure. Neither type is a disguised boolean. They carry the successful value, and Result preserves information needed to explain or recover from the error.
Use match when both outcomes deserve visible behavior. if let Some(item) = lookup() is compact when you only care about the present case. map transforms a value inside Some or Ok without inventing a value for the other case.
Keep learning, for free
The rest of this lesson is waiting for you.
Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.
No payment details. Your account opens the complete Academy.