fix: apply cargo fix recommendations
authorMA Beaudet <ma@beaudet.xyz>
Wed, 10 Nov 2021 21:10:34 +0000 (22:10 +0100)
committerMA Beaudet <ma@beaudet.xyz>
Wed, 10 Nov 2021 21:10:34 +0000 (22:10 +0100)
src/card.rs
src/evaluator.rs
src/lib.rs

index ce1e989..bd4a1fc 100644 (file)
@@ -6,7 +6,7 @@ use crate::{constants::PRIMES, errors::ParseCardError, Rules};
 use serde::{Deserialize, Serialize};
 
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Default, Clone, Hash, PartialEq)]
+#[derive(Debug, Default, Clone, PartialEq)]
 pub struct Cards(Vec<Card>);
 
 impl Cards {
@@ -146,7 +146,7 @@ impl Deck {
     ) -> Result<Vec<Cards>, ParseCardError> {
         (0..player_nb)
             .into_iter()
-            .map(|_| Ok(self.deal_with_rules(rules)?))
+            .map(|_| self.deal_with_rules(rules))
             .collect()
     }
 
@@ -159,7 +159,7 @@ impl Deck {
     }
 
     #[cfg(feature = "rand")]
-    pub fn shuffle<'a>(&'a mut self) -> &'a mut Deck {
+    pub fn shuffle(&mut self) -> &mut Self {
         use rand::prelude::*;
         let mut rng = thread_rng();
         self.0 .0.shuffle(&mut rng);
@@ -185,7 +185,7 @@ impl Default for Deck {
 }
 
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Clone, Copy, Hash)]
+#[derive(Debug, Clone, Copy)]
 #[repr(transparent)]
 pub struct Card(u32);
 
index ce9f10b..91076f4 100644 (file)
@@ -50,7 +50,7 @@ impl Evaluator {
         self
     }
 
-    pub fn hands<'a>(&'a mut self, hands: &Vec<Cards>) -> &'a mut Evaluator {
+    pub fn hands<'a>(&'a mut self, hands: &[Cards]) -> &'a mut Evaluator {
         self.hands.extend_from_slice(hands);
         self
     }
@@ -83,7 +83,7 @@ impl Evaluator {
             Ok(())
         }
 
-        parse_args(&self)?;
+        parse_args(self)?;
 
         let hands: Vec<Vec<u32>> = self.hands.iter().map(|h| h.clone().into()).collect();
         let table: Vec<u32> = self.table.clone().into();
@@ -130,10 +130,9 @@ impl Evaluator {
     pub fn eval_7hand(cards: &[u32]) -> Result<u16, EvaluateCardError> {
         let mut subhand: [u32; 5] = [0; 5];
         let mut best = 9999;
-
-        for i in 0..21 {
-            for j in 0..5 {
-                subhand[j] = cards[..][PERM7[i][j] as usize];
+        for perm in &PERM7 {
+            for (i, card) in subhand.iter_mut().enumerate() {
+                *card = cards[..][perm[i] as usize];
             }
             let q = Evaluator::eval_5hand(&subhand)?;
             if q < best {
index f1c94c6..28deb5c 100644 (file)
@@ -52,12 +52,12 @@ impl Default for Algorithm {
 }
 
 pub fn report(result: &HashMap<usize, u16>) -> (&usize, &u16) {
-    for (p, s) in result.into_iter() {
+    for (p, s) in result.iter() {
         println!("Player {}: Score {}", p, s);
         println!("Hand value: {}", VALUE_STR[hand_rank(*s) as usize]);
         println!();
     }
-    let winner = result.iter().min_by(|a, b| a.1.cmp(&b.1)).unwrap().clone();
+    let winner = result.iter().min_by(|a, b| a.1.cmp(b.1)).unwrap();
     println!("Winner: Player {} with score {}", winner.0, winner.1);
     winner
 }