Add 'NUM_VARIANTS' constant to all 'board' enums
This commit is contained in:
parent
3f93417092
commit
42126e1c88
5 changed files with 23 additions and 8 deletions
|
|
@ -14,10 +14,13 @@ pub enum CastleRights {
|
|||
}
|
||||
|
||||
impl CastleRights {
|
||||
/// The number of [CastleRights] variants.
|
||||
pub const NUM_VARIANTS: usize = 4;
|
||||
|
||||
/// Convert from a castle rights index into a [CastleRights] type.
|
||||
#[inline(always)]
|
||||
pub fn from_index(index: usize) -> Self {
|
||||
assert!(index < 4);
|
||||
assert!(index < Self::NUM_VARIANTS);
|
||||
// SAFETY: we know the value is in-bounds
|
||||
unsafe { Self::from_index_unchecked(index) }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue