From efa281e75c0ba7218ada583a671eee65f8720cda Mon Sep 17 00:00:00 2001 From: Geoffrey Allott Date: Tue, 23 Mar 2021 20:10:33 +0000 Subject: [PATCH] fix for older rustc --- src/game/poker/holdem.rs | 5 ++--- src/util/array.rs | 12 ++++++++++++ src/util/mod.rs | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 src/util/array.rs diff --git a/src/game/poker/holdem.rs b/src/game/poker/holdem.rs index ed64bff..5361ac9 100644 --- a/src/game/poker/holdem.rs +++ b/src/game/poker/holdem.rs @@ -1,6 +1,5 @@ use std::cmp::Ordering; use std::collections::{HashMap, HashSet}; -use std::convert::TryInto; use itertools::Itertools; @@ -8,7 +7,7 @@ use crate::card::{Card, FIFTY_TWO_CARD_DECK}; use crate::rng::{Seed, WaveRng}; use crate::seats::Seats; use crate::username::Username; -use crate::util::{max::IteratorMaxItems, timestamp::Timestamp}; +use crate::util::{array::TryIntoArray, max::IteratorMaxItems, timestamp::Timestamp}; use super::super::{Action, ActionError, DealerAction, Game, StartCondition, UserAction, ValidatedUserAction}; @@ -640,7 +639,7 @@ impl Game for TexasHoldEm { .iter() .sorted_by_key(|&(username, _)| username) .map(|(&username, hand)| (username, hand.iter().chain(self.community.iter()).cloned().collect::>())) - .filter_map(|(username, cards)| cards.try_into().ok().map(rank_7_card_hand).map(|hand| (username, hand))) + .filter_map(|(username, cards)| cards.try_into_array().ok().map(rank_7_card_hand).map(|hand| (username, hand))) .max_items_by_key(|(_, hand)| *hand); info!("Showdown: community: {:?}", self.community); info!("Showdown: all hands: {:?}", self.hands); diff --git a/src/util/array.rs b/src/util/array.rs new file mode 100644 index 0000000..882dd21 --- /dev/null +++ b/src/util/array.rs @@ -0,0 +1,12 @@ +pub trait TryIntoArray { + fn try_into_array(self) -> Result; +} + +impl TryIntoArray<[T; 7]> for Vec { + fn try_into_array(self) -> Result<[T; 7], usize> { + match *self { + [a, b, c, d, e, f, g] => Ok([a, b, c, d, e, f, g]), + _ => Err(self.len()), + } + } +} diff --git a/src/util/mod.rs b/src/util/mod.rs index 1a4b272..6eddd82 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,3 +1,4 @@ +pub mod array; pub mod dedup; pub mod max; pub mod timestamp; -- 2.34.1