Add 'Color::iter'
This commit is contained in:
parent
066d442823
commit
bd9238d686
1 changed files with 7 additions and 0 deletions
|
|
@ -11,6 +11,13 @@ impl Color {
|
||||||
/// The number of [Color] variants.
|
/// The number of [Color] variants.
|
||||||
pub const NUM_VARIANTS: usize = 2;
|
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.
|
/// Convert from a color index into a [Color] type.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn from_index(index: usize) -> Self {
|
pub fn from_index(index: usize) -> Self {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue