flâneur

Unwrap - 100 Exercises To Learn Rust

rust-exercises.com · 238 words · saved by 1 readers

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