ckc_rs/cards/
mod.rs

1use crate::cards::five::Five;
2use crate::{CKCNumber, CardNumber};
3use core::slice::Iter;
4
5pub mod binary_card;
6pub mod five;
7pub mod four;
8pub mod seven;
9pub mod six;
10pub mod three;
11pub mod two;
12
13pub trait HandRanker {
14    fn hand_rank(&self) -> crate::hand_rank::HandRank {
15        crate::hand_rank::HandRank::from(self.hand_rank_value())
16    }
17
18    fn hand_rank_validated(&self) -> crate::hand_rank::HandRank {
19        crate::hand_rank::HandRank::from(self.hand_rank_value_validated())
20    }
21
22    fn hand_rank_value(&self) -> crate::hand_rank::HandRankValue {
23        let (hrv, _) = self.hand_rank_value_and_hand();
24        hrv
25    }
26
27    fn hand_rank_value_and_hand(&self) -> (crate::hand_rank::HandRankValue, Five);
28
29    fn hand_rank_value_validated(&self) -> crate::hand_rank::HandRankValue;
30}
31
32pub trait HandValidator {
33    fn are_unique(&self) -> bool;
34
35    fn first(&self) -> CKCNumber;
36
37    #[must_use]
38    fn sort(&self) -> Self;
39
40    fn sort_in_place(&mut self);
41
42    fn contain_blank(&self) -> bool {
43        self.iter().any(|c| c == &CardNumber::BLANK)
44    }
45
46    /// A corrupt hand is one where any of the values in the array doesn't correspond to any
47    /// recognized `CardNumber` or is blank.
48    fn is_corrupt(&self) -> bool {
49        self.iter().any(|c| CardNumber::filter(*c) == CardNumber::BLANK)
50    }
51
52    fn is_valid(&self) -> bool {
53        self.are_unique() && !self.is_corrupt()
54    }
55
56    fn iter(&self) -> Iter<'_, CKCNumber>;
57}
58
59pub trait Permutator {
60    fn five_from_permutation(&self, permutation: [u8; 5]) -> Five;
61}