Add 'Color::iter'

This commit is contained in:
Bruno BELANYI 2022-07-23 15:32:56 +02:00
parent 066d442823
commit bd9238d686

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 color index into a [Color] type.
#[inline(always)]
pub fn from_index(index: usize) -> Self {