Recoverable Errors with Result - The Rust Programming Language
Most errors aren’t serious enough to require the program to stop entirely. Sometimes, when a function fails, it’s for a reason that you can easily interpret and respond to. For example, if you try to open a file and that operation fails because the file doesn’t exist, you might want to create the file instead of terminating the process. Recall from “Handling Potential Failure with Result” in Chapter 2 that the Result enum is defined as having two variants, Ok and Err, as follows: The T and E are generic type parameters: we’ll discuss generics in more detail in Chapter 10. What you need to know right now is that T represents the type of the value that will be returned in a success case within the Ok variant, and E represents the type of the error that will be returned in a failure case within the Err variant. Because Result has these generic type parameters, we can use the Result type and the functions defined on it in many different situations where the successful value and error value
Recoverable Errors with Result - The Rust Programming Language Keyboard shortcuts Press ← or → to navigate between chapters Press S or / to search in the book Press ? to show this help Press Esc to hide this help Auto Light Rust Coal Navy Ayu The Rust Programming Language Recoverable Errors with Result Most errors aren’t serious enough to require the program to stop entirely. Sometimes when a function fails, it’s for a reason that you can easily interpret and respond to. For example, if you try to open a file and that operation fails because the file doesn’t exist, you might want to create the
related reading
- Error Handling in Rust - Andrew Gallant's Blogburntsushi.net
- 100 Exercises To Learn Rustrust-exercises.com
- Generic Data Types - The Rust Programming Languagedoc.rust-lang.org
- References and Borrowing - The Rust Programming Languagedoc.rust-lang.org
- Programming a Guessing Game - The Rust Programming Languagedoc.rust-lang.org
- Generic Types, Traits, and Lifetimes - The Rust Programming Languagedoc.rust-lang.org
- Methods - The Rust Programming Languagedoc.rust-lang.org
- Defining an Enum - The Rust Programming Languagedoc.rust-lang.org
- A half-hour to learn Rustfasterthanli.me
- Rust Language Cheat Sheetcheats.rs
- Validating References with Lifetimes - The Rust Programming Languagedoc.rust-lang.org
- Variables and Mutability - The Rust Programming Languagedoc.rust-lang.org