[core] Directly index the array of Squares with a given index

In Square::from_index_unchecked, instead of using TryFrom to convert the index
to a square, just index directly into the Square::ALL array. This function is
already marked unsafe.
This commit is contained in:
Eryn Wells 2025-06-19 14:32:07 -07:00
parent 1d8a0dc3a4
commit 481ae70698

View file

@ -115,7 +115,9 @@ macro_rules! range_bound_struct {
coordinate_enum!(
Direction,
[North, NorthEast, East, SouthEast, South, SouthWest, West, NorthWest]
[
North, NorthEast, East, SouthEast, South, SouthWest, West, NorthWest
]
);
impl Direction {
@ -262,7 +264,7 @@ impl Square {
#[must_use]
pub unsafe fn from_index_unchecked(x: u8) -> Square {
debug_assert!((x as usize) < Self::NUM);
Self::try_from(x).unwrap_unchecked()
Self::ALL[x as usize]
}
#[inline]