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
Explore this link on the map →related reading
- Error Handling in Rust - Andrew Gallant's Blogburntsushi.net
- A half-hour to learn Rustfasterthanli.me
- Modular Errors in Rust - Sabrina Jewsonsabrinajewson.org
- Rust Solves The Issues With Exceptions · Dmitrii Aleksandrovhome.expurple.me
- Programming a Guessing Game - The Rust Programming Languagedoc.rust-lang.org
- The match Control Flow Construct - The Rust Programming Languagedoc.rust-lang.org
- Rust Language Cheat Sheetcheats.rs
- Defining an Enum - The Rust Programming Languagedoc.rust-lang.org
- How many options fit into a boolean? | MOND←TECH MAGAZINEherecomesthemoon.net
- Rewriting Bun in Rust | Bun Blogbun.com
- The registers of Rustwithout.boats
- Patterns for Defensive Programming in Rust | corrode Rust Consultingcorrode.dev