card:impls: *:iter_all and {Rank,Suit}::cards implement Clone.

Bit of a shame, but necessary for using ZipCartesian on them.
This commit is contained in:
2026-04-14 18:06:24 +01:00
committed by oreodave
parent f98b151c61
commit 334d9d1b6a

View File

@@ -7,7 +7,7 @@ ExactSizeIterator => Map<Range<i64>> is not an ESI. But Range<i32> is an ESI.
impl Rank {
/// Generate an iterator over all ranks.
pub fn iter_all() -> impl ExactSizeIterator<Item = Rank> {
pub fn iter_all() -> impl ExactSizeIterator<Item = Rank> + Clone {
(0i32..13)
.map(|n| n as i64)
.map(|n| Rank::try_from(n).unwrap())
@@ -15,7 +15,7 @@ impl Rank {
/// Generate an iterator over all cards within a rank, ordered by Suit. The
/// cards are all default initialised w.r.t. deck (0).
pub fn cards(self) -> impl ExactSizeIterator<Item = Card> {
pub fn cards(self) -> impl ExactSizeIterator<Item = Card> + Clone {
let n = self as i32;
((n * 4)..((n + 1) * 4)).map(|x| Card::from(x as i64))
}
@@ -23,13 +23,13 @@ impl Rank {
impl Suit {
/// Generate an iterator over all suits.
pub fn iter_all() -> impl ExactSizeIterator<Item = Suit> {
pub fn iter_all() -> impl ExactSizeIterator<Item = Suit> + Clone {
(0i32..4).map(|n| Suit::try_from(n as i64).unwrap())
}
/// Generate an iterator over all cards within a suit, ordered by Rank. The
/// cards are all default initialised in terms of deck (0).
pub fn cards(self) -> impl ExactSizeIterator<Item = Card> {
pub fn cards(self) -> impl ExactSizeIterator<Item = Card> + Clone {
Rank::iter_all().map(move |rank| Card::make_playing_card(0, rank, self))
}
}
@@ -47,7 +47,7 @@ impl PlayingCard {
/// Generate an iterator over all Playing Cards in the `nth` deck. By
/// construction this is in ascending order.
pub fn iter_all(n: i64) -> impl ExactSizeIterator<Item = Self> {
pub fn iter_all(n: i64) -> impl ExactSizeIterator<Item = Self> + Clone {
(0i32..52)
.map(|x| x as i64)
.map(move |x| x + (52 * n))
@@ -95,7 +95,7 @@ impl Card {
/// order.
///
/// Note that each deck gets two jokers.
pub fn iter_all(n: i64) -> impl Iterator<Item = Card> {
pub fn iter_all(n: i64) -> impl Iterator<Item = Card> + Clone {
// NOTE: I cannot make this into an ExactSizeIterator using the i32
// trick. Chain<ESI, ESI> is not an ESI, nor is FlatMap<T,U,T->U>
// (where T and U are ESIs).