Other than the Option type, a Result type can have two custom types, which means that Result provides additional information about the cause of the error. This is more expressive than returning Option, which returns a single type instance or None. However, this None instance can mean anything from failure to process to wrong input. This way, the Result type can be seen as a similar system as exceptions in other languages, but they are part of the regular workflow of a program. One example is a search, where a multitude of scenarios can happen:
- The desired value is found.
- The desired value is not found.
- The collection was invalid.
- The value was invalid.
How can you use the Result type effectively? Let's find out in this recipe!