From a8106ad0b58b284da0deaed138431a02292af71d Mon Sep 17 00:00:00 2001 From: Rhys Lloyd Date: Wed, 10 Jun 2026 20:39:05 -0700 Subject: [PATCH] iterators for Tableau and Foundation --- klondike/src/lib.rs | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/klondike/src/lib.rs b/klondike/src/lib.rs index 425201f..56793d2 100644 --- a/klondike/src/lib.rs +++ b/klondike/src/lib.rs @@ -164,6 +164,33 @@ impl Tableau { }) } } +pub struct TableauIter { + tableau: Option, +} +impl TableauIter { + pub const fn new() -> Self { + Self { + tableau: Some(Tableau::ITER_BEGIN), + } + } +} +impl Iterator for TableauIter { + type Item = Tableau; + fn next(&mut self) -> Option { + let tableau = self.tableau?; + self.tableau = tableau.next(); + Some(tableau) + } +} +impl IntoIterator for Tableau { + type Item = Self; + type IntoIter = TableauIter; + fn into_iter(self) -> Self::IntoIter { + TableauIter { + tableau: Some(self), + } + } +} #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub enum Foundation { @@ -184,6 +211,33 @@ impl Foundation { }) } } +pub struct FoundationIter { + foundation: Option, +} +impl FoundationIter { + pub const fn new() -> Self { + Self { + foundation: Some(Foundation::ITER_BEGIN), + } + } +} +impl Iterator for FoundationIter { + type Item = Foundation; + fn next(&mut self) -> Option { + let foundation = self.foundation?; + self.foundation = foundation.next(); + Some(foundation) + } +} +impl IntoIterator for Foundation { + type Item = Self; + type IntoIter = FoundationIter; + fn into_iter(self) -> Self::IntoIter { + FoundationIter { + foundation: Some(self), + } + } +} #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub enum KlondikePile {