card: make Rank|Suit::cards yield an iterator instead of a vector

This commit is contained in:
2026-04-03 05:35:38 +01:00
committed by oreodave
parent d9cc67d3d1
commit 555c8e127b

View File

@@ -47,8 +47,8 @@ impl Rank {
}
/** Generate an iterator over all cards within a rank, ordered by Suit. */
pub fn cards(&self) -> impl Iterator<Item = Card> {
let n = *self as i64;
pub fn cards(self) -> impl Iterator<Item = Card> {
let n = self as i64;
((n * 4)..((n + 1) * 4)).map(Card::from)
}
}
@@ -60,8 +60,8 @@ impl Suit {
}
/** Generate an iterator over all cards within a suit, ordered by Suit. */
pub fn cards(&self) -> impl Iterator<Item = Card> {
Rank::iter_all().map(|rank| Card::make_playing_card(rank, *self))
pub fn cards(self) -> impl Iterator<Item = Card> {
Rank::iter_all().map(move |rank| Card::make_playing_card(rank, self))
}
}