From d729d63c75f2032a6374c40f6061980d1677e721 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 6 Apr 2024 19:48:34 +0100 Subject: [PATCH] Add 'CastleRights::iter' --- src/board/castle_rights.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/board/castle_rights.rs b/src/board/castle_rights.rs index 5bd9d91..81cb5a6 100644 --- a/src/board/castle_rights.rs +++ b/src/board/castle_rights.rs @@ -17,6 +17,18 @@ impl CastleRights { /// The number of [CastleRights] variants. pub const NUM_VARIANTS: usize = 4; + const ALL: [Self; Self::NUM_VARIANTS] = [ + Self::NoSide, + Self::KingSide, + Self::QueenSide, + Self::BothSides, + ]; + + /// Iterate over all castle-rights variants. + pub fn iter() -> impl Iterator { + Self::ALL.iter().cloned() + } + /// Convert from a castle rights index into a [CastleRights] type. /// /// # Panics