From dd0011d1f2783c403d6c0069b1b6c398fbdc0fce Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Wed, 1 Apr 2026 03:42:42 +0100 Subject: [PATCH] card|classifier: young clippy up in this mf --- src/card.rs | 4 ++-- src/classifier.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/card.rs b/src/card.rs index afd1a1a..50b63ae 100644 --- a/src/card.rs +++ b/src/card.rs @@ -37,14 +37,14 @@ impl Card { pub fn rank(&self) -> Option { match self { Self::Joker(_) => None, - Self::PlayingCard { rank: rank, .. } => Some(*rank), + Self::PlayingCard { rank, .. } => Some(*rank), } } pub fn suit(&self) -> Option { match self { Self::Joker(_) => None, - Self::PlayingCard { suit: suit, .. } => Some(*suit), + Self::PlayingCard { suit, .. } => Some(*suit), } } } diff --git a/src/classifier.rs b/src/classifier.rs index 906957d..d9bc404 100644 --- a/src/classifier.rs +++ b/src/classifier.rs @@ -29,7 +29,7 @@ pub enum Hand { impl Hand { pub fn classify(cards: &[Card]) -> Option { let num_jokers = cards.iter().filter(|c| c.is_joker()).count(); - if cards.len() == 0 || num_jokers == cards.len() { + if cards.is_empty() || num_jokers == cards.len() { None } else { let mut new_cards: Vec = Vec::new(); @@ -68,7 +68,7 @@ impl Hand { } } -/** NOTE: the assumptions of the following functions are: +/* NOTE: the assumptions of the following functions are: 1) The arguments are not all jokers 2) The arguments are sorted i.e. c_n < c_n+1 for all n. @@ -118,9 +118,9 @@ fn hand_type(num_jokers: usize, cards: &[Card]) -> Option { Some(PokerType::FiveKind) } else if num_jokers + highest_rank_freq == 4 { Some(PokerType::FourKind) - } else if num_jokers == 1 && num_pairs == 2 { - Some(PokerType::FullHouse) - } else if (num_pairs > 0 && highest_rank_freq == 3) { + } else if (num_jokers == 1 && num_pairs == 2) + || num_pairs > 0 && highest_rank_freq == 3 + { Some(PokerType::FullHouse) } else if is_straight { Some(PokerType::Straight) @@ -138,7 +138,7 @@ fn classify_poker_hand(num_jokers: usize, cards: &[Card]) -> Option { // NOTE: num_jokers in [0, 4] hand_type(num_jokers, cards) - .and_then(|ptype| Some(Hand::make_poker_hand(ptype, cards))) + .map(|ptype| Hand::make_poker_hand(ptype, cards)) } /*