Switch from Orca to Dolphin. Finish up removing code to be implemented.

This commit is contained in:
Nathan Stocks
2021-06-15 22:18:18 -06:00
parent 6159d01739
commit eb78fe0eab
2 changed files with 30 additions and 43 deletions

View File

@@ -1,22 +1,22 @@
// START IN lib.rs!
use aquarium::Orca;
use aquarium::Dolphin;
// (You already did #1 in lib.rs, right?)
// 2a. Uncomment and finish the play_time function below
// - Bring anyhow::Result into scope with a `use` statement
// - Have the function return a Result<Vec<String>>. The vector of Strings will represent successful
// outcomes of various performances.
// - Have the play_time function return a `Result<Vec<String>>`. The vector of Strings will
// represent successful outcomes of various dolphin tricks.
// fn play_time(orca: &Orca) -> ... {
// fn play_time(dolphin: &Dolphin) -> ... {
// let mut responses = vec![];
// // 2b. There are three methods on the Orca struct:
// // 2b. There are three methods on the Dolphin struct:
// // - .say_your_name()
// // - .flip()
// // - .shake_hands()
// //
// // For each of the three methods above:
// // - Call the method on `orca`, using the `?` operator to unwrap the value / return the error
// // - Call the method on `dolphin`, using the `?` operator to unwrap the value / return the error
// // - Push the unwrapped string onto the `responses` vector using the .push() method
// // let response = ... // this can be done with an intermediate variable...
@@ -26,37 +26,37 @@ use aquarium::Orca;
// }
fn main() {
let orcas = vec![
Orca {
let dolphins = vec![
Dolphin {
name: "Augustinius".into(),
age: 7,
hungry: false,
},
Orca {
Dolphin {
name: "Bitty".into(),
age: 2,
hungry: true,
},
Orca {
Dolphin {
name: "Carson".into(),
age: 5,
hungry: true,
},
Orca {
Dolphin {
name: "Devin".into(),
age: 6,
hungry: false,
},
];
for orca in &orcas {
match play_time(orca) {
for dolphin in &dolphins {
match play_time(dolphin) {
Ok(responses) => {
println!("{} did a FABULOUS PERFORMANCE!", orca.name);
println!("{} did a FABULOUS PERFORMANCE!", dolphin.name);
for response in responses {
println!(" {}", response);
}
}
Err(e) => println!("{} can't perform today: {}", orca.name, e.to_string()),
Err(e) => println!("{} can't perform today: {}", dolphin.name, e.to_string()),
}
}
}