April 2026
Intermediate
631 pages
16h 20m
English
Just like an Option enum, which provides the ability to handle situations where you might have some value or no value, Rust has a built-in enum called Result. This enum handles situations where an operation can be successful, thereby returning a valid value, or may fail, thereby resulting in an error.
In the following sections, we’ll explain the motivation behind Result, examine the results of matching, and explore the related ? operator.
Consider the function shown in Listing 5.26 once more. This function lacks a clear mechanism to check if a student exists in the database. Currently, if no student name matches, the function implicitly assumes the student doesn’t exist and returns None. However, within ...
Read now
Unlock full access