From 454864ec86ea3b7081bdb9e0a2f83d365d8e297e Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Wed, 28 Dec 2022 07:26:26 -0500 Subject: Fix clippy errors --- protocol/src/bridge_engine.rs | 36 ++++++++++++++---------------------- protocol/src/card.rs | 4 ++-- protocol/src/simple_bots.rs | 2 +- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/protocol/src/bridge_engine.rs b/protocol/src/bridge_engine.rs index 7d69b82..a3aa12e 100644 --- a/protocol/src/bridge_engine.rs +++ b/protocol/src/bridge_engine.rs @@ -735,19 +735,11 @@ impl GameState { } pub fn is_bidding(&self) -> bool { - if let GameState::Bidding { .. } = self { - true - } else { - false - } + matches!(self, GameState::Bidding { .. }) } pub fn is_playing(&self) -> bool { - if let GameState::Play { .. } = self { - true - } else { - false - } + matches!(self, GameState::Play { .. }) } pub fn bidding(&self) -> Result<&BiddingState, anyhow::Error> { @@ -810,8 +802,8 @@ impl GameState { #[derive(PartialEq, Eq, Clone, Debug, Serialize, Deserialize)] pub struct GameResult; -impl Into for PlayResult { - fn into(self) -> GameResult { +impl From for GameResult { + fn from(_val: PlayResult) -> GameResult { GameResult } } @@ -960,18 +952,18 @@ impl Default for TableState { } } -impl Into for MoveResult { - fn into(self) -> TableState { - match self { +impl From> for TableState { + fn from(val: MoveResult) -> Self { + match val { MoveResult::Current(game) => TableState::Game(game), MoveResult::Next(result) => TableState::Result(result), } } } -impl Into for GameState { - fn into(self) -> TableState { - TableState::Game(self) +impl From for TableState { + fn from(val: GameState) -> Self { + TableState::Game(val) } } @@ -1175,7 +1167,7 @@ mod tests { } fn mkcards(s: &str) -> Vec { - s.split(" ").map(mkcard).collect() + s.split(' ').map(mkcard).collect() } fn example_deal() -> Deal { @@ -1220,7 +1212,7 @@ mod tests { let game_state = GameState::new(mini_deal(), Player::North); assert_eq!(game_state.deal(), &mini_deal()); assert_eq!(game_state.dealer(), Player::North); - assert_eq!(game_state.is_bidding(), true); + assert!(game_state.is_bidding()); info!("Start bidding with game state {game_state:#?}"); let raise = |s| Bid::Raise(Raise::from_str(s).unwrap()); @@ -1240,8 +1232,8 @@ mod tests { .current() .unwrap(); info!("Start playing with game state {game_state:#?}"); - assert_eq!(game_state.is_bidding(), false); - assert_eq!(game_state.is_playing(), true); + assert!(!game_state.is_bidding()); + assert!(game_state.is_playing()); } #[test] diff --git a/protocol/src/card.rs b/protocol/src/card.rs index 30cf822..771d5e9 100644 --- a/protocol/src/card.rs +++ b/protocol/src/card.rs @@ -187,11 +187,11 @@ impl std::str::FromStr for Card { type Err = anyhow::Error; fn from_str(s: &str) -> std::result::Result { - let stripped = s.replace(" ", ""); + let stripped = s.replace(' ', ""); let mut chars = stripped.chars(); let suit = chars .next() - .ok_or(anyhow!("missing parts: {}", s))? + .ok_or_else(|| anyhow!("missing parts: {}", s))? .to_string() .parse()?; let rank = chars.collect::().parse()?; diff --git a/protocol/src/simple_bots.rs b/protocol/src/simple_bots.rs index 2c2832c..ed1cd14 100644 --- a/protocol/src/simple_bots.rs +++ b/protocol/src/simple_bots.rs @@ -104,7 +104,7 @@ mod tests { } fn mkcards(s: &str) -> Vec { - s.split(" ").map(mkcard).collect() + s.split(' ').map(mkcard).collect() } fn example_deal() -> Deal { -- cgit v1.2.3