If you find this helpful, please like, bookmark, and follow. To keep learning along, follow this series.
9.2.1 The Result Enum
Usually, errors are not serious enough to stop the entire program. A function may fail or encounter an error for reasons that are often easy to explain and respond to. For example, a program may try to open a file that does not exist; in that case, you would usually consider creating the file rather than terminating the program immediately.
Rust provides the Result enum to handle these potentially failing cases. Its definition is:
enum Result<T, E> {
Ok(T),
Err(E),
}
It has two generic type parameters, T and E, and two variants, each associated with data. Ok is associated with T, and Err is associated with E. Generics will be discussed in Chapter 10. For now, just know that T is the type of the data returned by the Ok variant when the operation succeeds, and E is the type of the error returned by the Err variant when the oper
Discussion
Take the lead—comment now
Lead the way—your insights can inspire others.