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

@@ -41,7 +41,11 @@ fn main() {
// Hint: .to_uppercase() is a method on `str` which returns a String // Hint: .to_uppercase() is a method on `str` which returns a String
let words = vec!["autobot", "beach", "car", "decepticon", "energon", "frothy"]; let words = vec!["autobot", "beach", "car", "decepticon", "energon", "frothy"];
let transformed = words.into_iter().filter(|w| !w.contains("h")).map(|w| w.to_uppercase()).collect::<Vec<String>>(); let transformed = words
.into_iter()
.filter(|w| !w.contains("h"))
.map(|w| w.to_uppercase())
.collect::<Vec<String>>();
println!("Transformed: {:?}", transformed); println!("Transformed: {:?}", transformed);
// Challenge: // Challenge:

View File

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

View File

@@ -3,14 +3,12 @@
use aquarium::Dolphin; use aquarium::Dolphin;
// Silence some warnings so they don't distract from the exercise. // Silence some warnings so they don't distract from the exercise.
#[allow(clippy::vec_init_then_push)] #[allow(clippy::vec_init_then_push)]
// (You already did #1 in lib.rs, right?) // (You already did #1 in lib.rs, right?)
// //
// 2a. Uncomment and finish the play_time function below // 2a. Uncomment and finish the play_time function below
// - Bring anyhow::Result into scope with a `use` statement // - Bring anyhow::Result into scope with a `use` statement
// - Have the play_time function return a `Result<Vec<String>>`. The vector of Strings will // - Have the play_time function return a `Result<Vec<String>>`. The vector of Strings will
// represent successful outcomes of various dolphin tricks. // represent successful outcomes of various dolphin tricks.
use anyhow::Result; use anyhow::Result;
fn play_time(dolphin: &Dolphin) -> Result<Vec<String>> { fn play_time(dolphin: &Dolphin) -> Result<Vec<String>> {

View File

@@ -6,7 +6,7 @@
// //
// Hint: You need to update Cargo.toml to add the `log` dependency, first. // Hint: You need to update Cargo.toml to add the `log` dependency, first.
use log::{error, warn, info, debug, trace}; use log::{debug, error, info, trace, warn};
#[derive(Debug)] #[derive(Debug)]
pub struct Frog { pub struct Frog {

View File

@@ -2,7 +2,9 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion};
use testing::sploosh; use testing::sploosh;
pub fn sploosh_benchmark(c: &mut Criterion) { pub fn sploosh_benchmark(c: &mut Criterion) {
c.bench_function("sploosh", |b| b.iter(|| sploosh(black_box(8), black_box(9), black_box(10)))); c.bench_function("sploosh", |b| {
b.iter(|| sploosh(black_box(8), black_box(9), black_box(10)))
});
} }
criterion_group!(benches, sploosh_benchmark); criterion_group!(benches, sploosh_benchmark);

View File

@@ -1,4 +1,4 @@
use testing::{sploosh, splish}; use testing::{splish, sploosh};
#[test] #[test]
pub fn test_sploosh_splish() { pub fn test_sploosh_splish() {

View File

@@ -113,13 +113,7 @@ fn main() {
} }
}); });
for number in vec![ for number in vec![1, 2, 3, 4, 5] {
1,
2,
3,
4,
5,
] {
println!("NUMBER: {}", number); println!("NUMBER: {}", number);
let _ = tx.send(number); let _ = tx.send(number);
} }

View File

@@ -17,7 +17,7 @@ impl Default for Party {
Self { Self {
at_restaurant: true, at_restaurant: true,
num_people: 8, num_people: 8,
cake: Cake::Chocolate cake: Cake::Chocolate,
} }
} }
} }
@@ -110,7 +110,10 @@ fn main() {
// consuming it. Change the code above to pass in a &party. Then uncomment and run the code // consuming it. Change the code above to pass in a &party. Then uncomment and run the code
// below. After all, you want to smell your cake and eat it, too! // below. After all, you want to smell your cake and eat it, too!
println!("Yum! I'm eating this cake: {:?}. Oops, I dropped it on the floor.", party.cake); println!(
"Yum! I'm eating this cake: {:?}. Oops, I dropped it on the floor.",
party.cake
);
} }
pub fn admire_cake(cake: Cake) { pub fn admire_cake(cake: Cake) {