add suggestions from clippy lints
authorGeoffrey Allott <geoffrey@allott.email>
Sat, 6 Mar 2021 11:18:38 +0000 (11:18 +0000)
committerGeoffrey Allott <geoffrey@allott.email>
Sat, 6 Mar 2021 13:32:12 +0000 (13:32 +0000)
src/client.rs
src/dealer.rs
src/game/poker/holdem.rs
src/seats.rs
src/server.rs
src/util/dedup.rs

index b2bee747ccf3db510f7328b05f83a188a894fd0f..dd11589a357173ee4c24d742eab775b8ccbc7b3d 100644 (file)
@@ -56,8 +56,8 @@ impl ConnectionState {
                 }
                 _ => empty().boxed(),
             },
-            ClientInterest::Game { id } => match &mut self.client {
-                &mut ClientState::LoggedIn { username, state: LoggedInState::InGame { ref mut game } } if game.id() == id => {
+            ClientInterest::Game { id } => match self.client {
+                ClientState::LoggedIn { username, state: LoggedInState::InGame { ref mut game } } if game.id() == id => {
                     let id = game.id();
                     let from = game.actions_len();
                     match self.server.game_state(id, from).await {
@@ -82,7 +82,7 @@ impl ConnectionState {
 
     pub fn interests(&self) -> HashSet<ClientInterest> {
         let mut ret = HashSet::new();
-        if let &ClientState::LoggedIn { username, ref state } = &self.client {
+        if let ClientState::LoggedIn { username, ref state } = self.client {
             ret.insert(ClientInterest::User { username });
             match state {
                 LoggedInState::Idle => {}
@@ -124,7 +124,7 @@ impl ConnectionState {
             }
             (&mut ClientState::LoginAuthIssued { username, ref challenge }, ClientMessage::LoginAuthResponse { signature }) => {
                 if self.server.verify(username, &challenge, &signature).await {
-                    self.client = ClientState::LoggedIn { username: username.clone(), state: LoggedInState::Idle };
+                    self.client = ClientState::LoggedIn { username, state: LoggedInState::Idle };
                     ServerMessage::LoginSuccess
                 } else {
                     self.client = ClientState::Connected;
@@ -138,7 +138,7 @@ impl ConnectionState {
                         for game in games.clone() {
                             game_list.push(game);
                         }
-                        self.client = ClientState::LoggedIn { username: username.clone(), state: LoggedInState::InLobby { game_list } };
+                        self.client = ClientState::LoggedIn { username, state: LoggedInState::InLobby { game_list } };
                         ServerMessage::JoinLobbySuccess { games }
                     }
                     Err(err) => ServerMessage::JoinLobbyFailure { reason: err.to_string() },
@@ -158,7 +158,7 @@ impl ConnectionState {
                                 error!("Action from database failed to apply: {}", err);
                             }
                         }
-                        self.client = ClientState::LoggedIn { username: username.clone(), state: LoggedInState::InGame { game } };
+                        self.client = ClientState::LoggedIn { username, state: LoggedInState::InGame { game } };
                         ServerMessage::JoinGameSuccess { summary, actions: actions_view }
                     }
                     (Err(err), _, _) | (_, Err(err), _) | (_, _, Err(err)) => ServerMessage::JoinGameFailure { reason: err.to_string() },
index c7a8b62c756c562e975f75de4f69079cc1b27500..9dece12a31455f439a9804530d39ff96c263b3b5 100644 (file)
@@ -39,7 +39,7 @@ impl Dealer {
 
     pub async fn start(mut self, update_stream: Receiver<ClientInterest>) {
         let mut update_stream = update_stream.dedup_ready();
-        while let Some(_) = update_stream.next().await {
+        while update_stream.next().await.is_some() {
             match self.retrieve_updates().await {
                 Ok(Termination::Continue) => continue,
                 Ok(Termination::Break) => break,
index 3ac130b23bf6cb993ceb963e407a1f0640e99155..10bf4828fab3d9b49a7e7d55ede8df406c1607d7 100644 (file)
@@ -1,3 +1,4 @@
+use std::cmp::Ordering;
 use std::collections::{HashMap, HashSet};
 use std::convert::TryInto;
 
@@ -165,7 +166,7 @@ impl TexasHoldEm {
                 }
             }
         }
-        self.all_bets_are_in() && self.all_bets_are_equal() || self.players_able_to_bet() <= 1 && self.bets.len() == 0
+        self.all_bets_are_in() && self.all_bets_are_equal() || self.players_able_to_bet() <= 1 && self.bets.is_empty()
     }
 
     fn remove_ghosts(&mut self) -> Result<(), ActionError> {
@@ -175,7 +176,7 @@ impl TexasHoldEm {
             }
         }
         self.ghosts.retain(|_, &mut turns| turns > 0);
-        for (_, turns) in &mut self.ghosts {
+        for turns in self.ghosts.values_mut() {
             *turns -= 1;
         }
         Ok(())
@@ -239,24 +240,19 @@ impl Game for TexasHoldEm {
             (_, Action::Fold) | (_, Action::Bet { .. }) if self.active != Some(username) => Err(ActionError::OutOfTurn),
             (_, Action::Fold) if self.chips_to_call(username) == 0 => Err(ActionError::CannotFold),
             (_, Action::Fold) => Ok(ValidatedUserAction(UserAction { timestamp, username, action: Action::Fold })),
-            (_, Action::Bet { chips }) => {
-                let stack = self.stack(username);
-                if chips > stack {
-                    Err(ActionError::NotEnoughChips)
-                } else if chips == stack {
-                    Ok(ValidatedUserAction(UserAction { timestamp, username, action: Action::Bet { chips } }))
-                } else {
+            (_, Action::Bet { chips }) => match chips.cmp(&self.stack(username)) {
+                Ordering::Greater => Err(ActionError::NotEnoughChips),
+                Ordering::Equal => Ok(ValidatedUserAction(UserAction { timestamp, username, action: Action::Bet { chips } })),
+                Ordering::Less => {
                     let to_call = self.chips_to_call(username);
                     let min_raise = self.min_raise();
-                    if chips < to_call {
-                        Err(ActionError::BetSizeTooSmall)
-                    } else if chips > to_call && chips < to_call + min_raise {
+                    if chips < to_call || chips > to_call && chips < to_call + min_raise {
                         Err(ActionError::BetSizeTooSmall)
                     } else {
                         Ok(ValidatedUserAction(UserAction { timestamp, username, action: Action::Bet { chips } }))
                     }
                 }
-            }
+            },
             (_, _) => Err(ActionError::InvalidActionForGameType),
         }
     }
index 66b489d4c1ad466e649337719ea3ddd3aa60f6a8..22588ee72280a846412e90f20d3c5a5dd7f135b6 100644 (file)
@@ -70,7 +70,7 @@ impl Seats {
     }
 
     pub fn contains_player(&self, username: Username) -> bool {
-        for (_, &player) in &self.players {
+        for &player in self.players.values() {
             if player == username {
                 return true;
             }
index a45956ab05c711fe094d56f0cbb8f1b5db052bb0..18c56a49a3917b9487c72e6485668268480b70ed 100644 (file)
@@ -97,7 +97,7 @@ impl ToRedisArgs for ClientInterest {
     }
 }
 
-const TAKE_ACTION_LUA_SCRIPT: &'static str = r#"
+const TAKE_ACTION_LUA_SCRIPT: &str = r#"
     local len = redis.call('llen', KEYS[1])
     local expected = tonumber(ARGV[1])
     if (len == expected) then
@@ -291,9 +291,8 @@ where
     where
         W: ?Sized + RedisWrite,
     {
-        match serde_json::to_vec(&self.0) {
-            Ok(bytes) => out.write_arg(&bytes),
-            Err(_) => return,
+        if let Ok(bytes) = serde_json::to_vec(&self.0) {
+            out.write_arg(&bytes);
         }
     }
 
index 056bfe132cc60569ae12766194acb4abbbe4b27b..fdcce76c59a0a76f010121e6e234a5efa35804e6 100644 (file)
@@ -31,7 +31,7 @@ where
         loop {
             match this.item {
                 Some(item) => match this.stream.as_mut().poll_next(cx) {
-                    Poll::Ready(Some(next)) if &next == &*item => continue,
+                    Poll::Ready(Some(next)) if next == *item => continue,
                     Poll::Ready(Some(mut next)) => {
                         swap(item, &mut next);
                         return Poll::Ready(Some(next));