How it works...
While the discussion of when to use Option and when to use Result takes place on a high level, Rust supports the transition between the two types with several functions. In addition to map(), and_then(), and so on (discussed in the Seamless error handling section in this chapter), these functions provide powerful and elegant ways to work with a variety of errors. In step 1 to step 4, we are slowly building a simple test that shows the applicability of the transpose function. It makes it possible to switch from Ok(Some(42)) to Some(Ok(42)) (notice the subtle difference) with a single call to a function. Similarly, the Err variation of the call goes from a regular Err(MyError) function to Some(Err(MyError)).
The remaining steps ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access