Start with the idea
Option says a value may be absent and that is unremarkable. Result says an operation failed and carries why. Converting between them is routine — ok_or turns absence into an error when the caller does need a reason.
Choose the enum according to the decision the caller must make. Option<T> represents an ordinary absence: a lookup may find no element. Result<T, E> represents a success or a failure whose reason is useful: parsing text can fail because the input is malformed. These meanings affect error messages, retries, and control flow. unwrap() removes the branch by panicking when the other variant appears, so it is a poor default at a user-input boundary.
Give a layered example. A cache lookup can return Option<Value>.
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.