Start with the idea
A missing optional value and an invalid supplied value describe different outcomes. Result<Option<T>, E> can express success with absence, success with a value, or failure. The example converts Option<Result<u16, ParseIntError>> using transpose, preserving all three cases without manufacturing a default port.
At an application boundary you may add contextual information such as a safe field name or a public operation ID. Preserve a useful source error when appropriate and avoid depending on human-readable error strings for control flow. A library can expose typed error cases, while an executable may aggregate errors for reporting.
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 754 lessons and algorithm steps are included.
No payment details. Your account opens the complete Academy.