How it works...
The Result type is important for creating code that integrates all of the possible function outcomes into the regular workflow. This eliminates the need for special handling of exceptions, making the code less verbose and easier to reason about. Since these types are known beforehand, the library can offer specialized functions as well, which is what we are looking at in this recipe.
In the first few steps (step 2 to step 4), we are working with positive results, which means values that are wrapped in the Ok enum variant. First, we covered the and_then function, which provides chaining of various functions that should only be executed when the initial Result is Ok. In the case of an Err return value of one of the functions ...
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