From 9ee73c9129e1b930d6c08a091564e8f1ccfdb944 Mon Sep 17 00:00:00 2001 From: Rorik Star Platinum Date: Tue, 9 Dec 2025 15:27:19 +0300 Subject: [PATCH] clippy issues --- rust/bottle-song/src/lib.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/rust/bottle-song/src/lib.rs b/rust/bottle-song/src/lib.rs index 9bf7a95..8df70e5 100644 --- a/rust/bottle-song/src/lib.rs +++ b/rust/bottle-song/src/lib.rs @@ -1,9 +1,9 @@ pub fn recite(start_bottles: u32, take_down: u32) -> String { let end_bottles = start_bottles - take_down; - + ((end_bottles + 1)..=start_bottles) .rev() - .map(|n| verse(n)) + .map(verse) .collect::>() .join("\n\n") } @@ -13,22 +13,29 @@ fn verse(n: u32) -> String { let next_bottle = bottle_str(n - 1).to_lowercase(); format!( - "{0} hanging on the wall,\n\ - {0} hanging on the wall,\n\ + "{current_bottle} hanging on the wall,\n\ + {current_bottle} hanging on the wall,\n\ And if one green bottle should accidentally fall,\n\ - There'll be {1} hanging on the wall.", - current_bottle, next_bottle + There'll be {next_bottle} hanging on the wall.", ) } fn bottle_str(n: u32) -> String { let count_str = match n { - 10 => "Ten", 9 => "Nine", 8 => "Eight", 7 => "Seven", 6 => "Six", - 5 => "Five", 4 => "Four", 3 => "Three", 2 => "Two", 1 => "One", + 10 => "Ten", + 9 => "Nine", + 8 => "Eight", + 7 => "Seven", + 6 => "Six", + 5 => "Five", + 4 => "Four", + 3 => "Three", + 2 => "Two", + 1 => "One", _ => "No", }; let plural = if n == 1 { "bottle" } else { "bottles" }; - + format!("{count_str} green {plural}") }