From 71dab0cf5cba9f28707f8b1c76c73d6c4c430366 Mon Sep 17 00:00:00 2001 From: Arthur Roberts Date: Mon, 24 Feb 2025 23:25:28 +0000 Subject: [PATCH] Couple of clippy lints Not 100% sure what the "must_use" is really for... so didn't "fix" them --- card_stuffs/src/lib.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/card_stuffs/src/lib.rs b/card_stuffs/src/lib.rs index a72d17a..5bdd237 100644 --- a/card_stuffs/src/lib.rs +++ b/card_stuffs/src/lib.rs @@ -20,10 +20,8 @@ pub enum Colour { impl Suit { pub fn colour(&self) -> Colour { match *self { - Suit::Heart => Colour::Red, - Suit::Diamond => Colour::Red, - Suit::Club => Colour::Black, - Suit::Spade => Colour::Black, + Suit::Heart | Suit::Diamond => Colour::Red, + Suit::Club | Suit::Spade => Colour::Black, } } } @@ -57,7 +55,7 @@ pub enum Value { } impl Value { - pub fn indexed_values(&self) -> u8 { + fn indexed_values(&self) -> u8 { // It might also make sense for Ace to be high... depends on context match self { Value::Ace => 1, @@ -119,7 +117,7 @@ pub enum StackingError { } impl Card { - pub fn can_be_placed_on_top(&self, top: Card) -> Result<(), StackingError> { + pub fn can_be_placed_on_top(&self, top: &Card) -> Result<(), StackingError> { // Can't be the same Colour if self.suit.colour() == top.suit.colour() { return Err(StackingError::SameColour); @@ -146,8 +144,8 @@ impl Default for Deck { for value in Value::iter() { array.push( Card { - suit: suit, - value: value, + suit, + value, } ); } @@ -173,22 +171,22 @@ mod tests { suit: Suit::Heart, value: Value::Six, }; - assert_eq!(testing_card.can_be_placed_on_top(bad_same_suit), Err(StackingError::SameColour)); + assert_eq!(testing_card.can_be_placed_on_top(&bad_same_suit), Err(StackingError::SameColour)); let bad_same_colour = Card { suit: Suit::Diamond, value: Value::Six, }; - assert_eq!(testing_card.can_be_placed_on_top(bad_same_colour), Err(StackingError::SameColour)); + assert_eq!(testing_card.can_be_placed_on_top(&bad_same_colour), Err(StackingError::SameColour)); let should_stack_card = Card { suit: Suit::Club, value: Value::Six, }; - assert_eq!(testing_card.can_be_placed_on_top(should_stack_card), Ok(())); + assert_eq!(testing_card.can_be_placed_on_top(&should_stack_card), Ok(())); let value_too_high = Card { suit: Suit::Club, value: Value::Seven, }; - let not_adj_error = testing_card.can_be_placed_on_top(value_too_high); + let not_adj_error = testing_card.can_be_placed_on_top(&value_too_high); if let Err(e) = not_adj_error { match e { StackingError::NotAdjacent(_, _) => assert!(true),