From 334d9d1b6a1bc3f9ed5dbc2ec57ab60e36e6d6d8 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Tue, 14 Apr 2026 18:06:24 +0100 Subject: [PATCH] card:impls: *:iter_all and {Rank,Suit}::cards implement Clone. Bit of a shame, but necessary for using ZipCartesian on them. --- src/card/impls.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/card/impls.rs b/src/card/impls.rs index 1679de1..f24a294 100644 --- a/src/card/impls.rs +++ b/src/card/impls.rs @@ -7,7 +7,7 @@ ExactSizeIterator => Map> is not an ESI. But Range is an ESI. impl Rank { /// Generate an iterator over all ranks. - pub fn iter_all() -> impl ExactSizeIterator { + pub fn iter_all() -> impl ExactSizeIterator + 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 { + pub fn cards(self) -> impl ExactSizeIterator + 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 { + pub fn iter_all() -> impl ExactSizeIterator + 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 { + pub fn cards(self) -> impl ExactSizeIterator + 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 { + pub fn iter_all(n: i64) -> impl ExactSizeIterator + 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 { + pub fn iter_all(n: i64) -> impl Iterator + Clone { // NOTE: I cannot make this into an ExactSizeIterator using the i32 // trick. Chain is not an ESI, nor is FlatMapU> // (where T and U are ESIs).