Rust’s expect operation extracts the success value from a Result. If the Result contains an error, it panics and adds a message you supply, making the failure more descriptive than unwrap’s default message. section 2.5.6 section 2.6
Adding context to a FizzBuzz failure
Replace a manual error match with `match fizzbuzz(x).expect("Failed to run fizzbuzz")`. For negative input, the program panics with `Failed to run fizzbuzz: GotNegative`, identifying both the operation and the error.
fn print_fizzbuzz(x: i32) {
match fizzbuzz(x).expect("Failed to run fizzbuzz") {
FizzBuzzValue::FizzBuzz => {
println!("FizzBuzz");
}
FizzBuzzValue::Fizz => {
println!("Fizz");
}
FizzBuzzValue::Buzz => {
println!("Buzz");
}
FizzBuzzValue::NotDivisible(num) => {
println!("{}", num);
}
}
}
Compare the shorter expect-based implementation with the earlier match that handles the error explicitly. section 2.5.6

