open_pql/base/
rank16_iter.rs

1use super::{Card64, Rank16, Suit};
2
3/// Iterator over the ranks in each suit of a Card64.
4///
5/// This iterator yields tuples of (Rank16, Suit) for each suit,
6/// where the Rank16 contains all ranks present in that suit.
7#[derive(Debug, Clone)]
8pub struct Rank16Iter {
9    c64: Card64,
10    suit_idx: u8,
11}
12
13impl Rank16Iter {
14    /// Creates a new `RanksIter` for the given Card64.
15    pub(crate) const fn new(c64: Card64) -> Self {
16        Self { c64, suit_idx: 0 }
17    }
18}
19
20impl Iterator for Rank16Iter {
21    type Item = (Rank16, Suit);
22
23    fn next(&mut self) -> Option<Self::Item> {
24        let suit = match self.suit_idx {
25            0 => Suit::S,
26            1 => Suit::H,
27            2 => Suit::D,
28            3 => Suit::C,
29            _ => return None,
30        };
31
32        self.suit_idx += 1;
33
34        Some((self.c64.ranks_by_suit(suit), suit))
35    }
36}