Add 'Color::iter'

This commit is contained in:
Bruno BELANYI 2022-07-23 15:32:56 +02:00
parent d97e7d646e
commit 0222ec4c2d

View file

@ -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<Item = Self> {
Self::ALL.iter().cloned()
}
/// Convert from a piece index into a [Color] type.
#[inline(always)]
pub fn from_index(index: usize) -> Self {