()
| 27 | // } |
| 28 | |
| 29 | fn main() { |
| 30 | let dolphins = vec![ |
| 31 | Dolphin { |
| 32 | name: "Augustinius".into(), |
| 33 | age: 7, |
| 34 | hungry: false, |
| 35 | }, |
| 36 | Dolphin { |
| 37 | name: "Bitty".into(), |
| 38 | age: 2, |
| 39 | hungry: true, |
| 40 | }, |
| 41 | Dolphin { |
| 42 | name: "Carson".into(), |
| 43 | age: 5, |
| 44 | hungry: true, |
| 45 | }, |
| 46 | Dolphin { |
| 47 | name: "Devin".into(), |
| 48 | age: 6, |
| 49 | hungry: false, |
| 50 | }, |
| 51 | ]; |
| 52 | for dolphin in &dolphins { |
| 53 | // Challenge: Change main() so that it returns a Result, and instead of handling the error |
| 54 | // that play_time returns, use the try (?) operator to only handle the success condition. |
| 55 | // |
| 56 | // If done correctly, the output of the program will become much shorter. Since play_time |
| 57 | // returns an Err variant the first time it is called, the try operator will return it from |
| 58 | // main(), which will end the program at the first error. anyhow's Result will take care of |
| 59 | // formatting the error output for us. |
| 60 | match play_time(dolphin) { |
| 61 | Ok(responses) => { |
| 62 | println!("{} did a FABULOUS PERFORMANCE!", dolphin.name); |
| 63 | for response in responses { |
| 64 | println!(" {}", response); |
| 65 | } |
| 66 | } |
| 67 | Err(e) => println!("{} can't perform today: {}", dolphin.name, e.to_string()), |
| 68 | } |
| 69 | } |
| 70 | } |
nothing calls this directly
no outgoing calls
no test coverage detected