summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2022-12-28 07:26:26 -0500
committerKjetil Orbekk <kj@orbekk.com>2022-12-28 07:26:36 -0500
commit454864ec86ea3b7081bdb9e0a2f83d365d8e297e (patch)
tree65a0dcfc8bf2033137609e4d198f3ffde5b5eb4b
parentde26af72d526c8a6154d65c5ab6ec3f94244e2ba (diff)
Fix clippy errors
-rw-r--r--protocol/src/bridge_engine.rs36
-rw-r--r--protocol/src/card.rs4
-rw-r--r--protocol/src/simple_bots.rs2
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<GameResult> for PlayResult {
- fn into(self) -> GameResult {
+impl From<PlayResult> for GameResult {
+ fn from(_val: PlayResult) -> GameResult {
GameResult
}
}
@@ -960,18 +952,18 @@ impl Default for TableState {
}
}
-impl Into<TableState> for MoveResult<GameState, GameResult> {
- fn into(self) -> TableState {
- match self {
+impl From<MoveResult<GameState, GameResult>> for TableState {
+ fn from(val: MoveResult<GameState, GameResult>) -> Self {
+ match val {
MoveResult::Current(game) => TableState::Game(game),
MoveResult::Next(result) => TableState::Result(result),
}
}
}
-impl Into<TableState> for GameState {
- fn into(self) -> TableState {
- TableState::Game(self)
+impl From<GameState> for TableState {
+ fn from(val: GameState) -> Self {
+ TableState::Game(val)
}
}
@@ -1175,7 +1167,7 @@ mod tests {
}
fn mkcards(s: &str) -> Vec<Card> {
- 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<Self, Self::Err> {
- 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::<String>().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<Card> {
- s.split(" ").map(mkcard).collect()
+ s.split(' ').map(mkcard).collect()
}
fn example_deal() -> Deal {