Unwrap - 100 Exercises To Learn Rust
Ticket::new now returns a Result instead of panicking on invalid inputs. What does this mean for the caller? Unlike exceptions, Rust's Result forces you to handle errors at the call site. If you call a function that returns a Result, Rust won't allow you to implicitly ignore the error case. When you call a function that returns a Result, you have two key options:
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 Unwrapping Ticket::new now returns a Result instead of panicking on invalid inputs. What does this mean for the caller? Failures can’t be (implicitly) ignored Unlike exceptions, Rust’s Result forces you to handle errors at the call site. If you call a function that returns a Result, Rust won’t allow you to implicitly ignore the error case. fn parse_int(s: &str) -> Result<i32, ParseIntError> { // ... } // This won't compile: we're…
saved by
related reading
- Recoverable Errors with Result - The Rust Programming Languagedoc.rust-lang.org
- Error Handling in Rust - Andrew Gallant's Blogburntsushi.net
- A half-hour to learn Rustfasterthanli.me
- Rust Solves The Issues With Exceptions · Dmitrii Aleksandrovhome.expurple.me
- Programming a Guessing Game - The Rust Programming Languagedoc.rust-lang.org
- Rust Language Cheat Sheetcheats.rs
- Modular Errors in Rust - Sabrina Jewsonsabrinajewson.org
- The match Control Flow Construct - The Rust Programming Languagedoc.rust-lang.org
- Rewriting Bun in Rust | Bun Blogbun.com
- Patterns for Defensive Programming in Rust | corrode Rust Consultingcorrode.dev
- How many options fit into a boolean? | MOND←TECH MAGAZINEherecomesthemoon.net
- Functions - The Rust Programming Languagedoc.rust-lang.org