cargo fmt

This commit is contained in:
2026-05-26 14:42:05 +04:00
parent 76cb232b1e
commit 47ed183cfe
9 changed files with 23 additions and 22 deletions

View File

@@ -24,7 +24,7 @@ pub enum DolphinError {
#[error("The dolphin is too young")]
TooYoung,
#[error("The dolphin's name is too long and annoying to say")]
LongName
LongName,
}
pub struct Dolphin {

View File

@@ -3,14 +3,12 @@
use aquarium::Dolphin;
// Silence some warnings so they don't distract from the exercise.
#[allow(clippy::vec_init_then_push)]
// (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 play_time function return a `Result<Vec<String>>`. The vector of Strings will
// represent successful outcomes of various dolphin tricks.
use anyhow::Result;
fn play_time(dolphin: &Dolphin) -> Result<Vec<String>> {
@@ -18,10 +16,10 @@ fn play_time(dolphin: &Dolphin) -> Result<Vec<String>> {
// 2b. Call the .say_your_name() method on `dolphin`, use `?` to unwrap the value, and push
// the value onto the `responses` vector.
//
let response = dolphin.say_your_name()?; // this can be done with an intermediate variable...
let response = dolphin.say_your_name()?; // this can be done with an intermediate variable...
responses.push(response); // ...or all on one line. Either way is fine!
//
// 2c. Do the same thing as #2b for the .flip() method
//
// 2c. Do the same thing as #2b for the .flip() method
responses.push(dolphin.flip()?);
//
// 2d. Do the same thing as #2b for the .shake_hands() method
@@ -56,7 +54,7 @@ fn main() -> Result<()> {
for dolphin in &dolphins {
// Challenge: Change main() so that it returns a Result, and instead of handling the error
// that play_time returns, use the try (?) operator to only handle the success condition.
//
//
// If done correctly, the output of the program will become much shorter. Since play_time
// returns an Err variant the first time it is called, the try operator will return it from
// main(), which will end the program at the first error. anyhow's Result will take care of