Add 'NUM_VARIANTS' constant to all 'board' enums

This commit is contained in:
Bruno BELANYI 2022-07-20 19:19:38 +02:00
parent 407f85c19b
commit d919b956ed
5 changed files with 23 additions and 8 deletions

View file

@ -15,7 +15,10 @@ pub enum File {
}
impl File {
const ALL: [Self; 8] = [
/// The number of [File] variants.
pub const NUM_VARIANTS: usize = 8;
const ALL: [Self; Self::NUM_VARIANTS] = [
Self::A,
Self::B,
Self::C,
@ -34,7 +37,7 @@ impl File {
/// Convert from a file index into a [File] type.
#[inline(always)]
pub fn from_index(index: usize) -> Self {
assert!(index < 8);
assert!(index < Self::NUM_VARIANTS);
// SAFETY: we know the value is in-bounds
unsafe { Self::from_index_unchecked(index) }
}