From 481ae70698c3ae15ce6827750a856237457d9d5b Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Thu, 19 Jun 2025 14:32:07 -0700 Subject: [PATCH] [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. --- core/src/coordinates.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/coordinates.rs b/core/src/coordinates.rs index 99a252e..308fc3e 100644 --- a/core/src/coordinates.rs +++ b/core/src/coordinates.rs @@ -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]