From bd9238d68626e92b621517cc573d6f4675e0daaf Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 23 Jul 2022 15:32:56 +0200 Subject: [PATCH] Add 'Color::iter' --- src/board/color.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/board/color.rs b/src/board/color.rs index 62fdd13..f909aca 100644 --- a/src/board/color.rs +++ b/src/board/color.rs @@ -11,6 +11,13 @@ impl Color { /// The number of [Color] variants. pub const NUM_VARIANTS: usize = 2; + const ALL: [Self; Self::NUM_VARIANTS] = [Self::White, Self::Black]; + + /// Iterate over all colors in order. + pub fn iter() -> impl Iterator { + Self::ALL.iter().cloned() + } + /// Convert from a color index into a [Color] type. #[inline(always)] pub fn from_index(index: usize) -> Self {