[core] Add #[must_use] to several methods in coordinates

This commit is contained in:
Eryn Wells 2024-07-13 07:21:21 -07:00
parent 7e45e49502
commit 534c022981

View file

@ -85,7 +85,6 @@ macro_rules! range_bound_struct {
&self.0 &self.0
} }
#[must_use]
$vis fn iter(&self) -> impl Iterator<Item = Self> { $vis fn iter(&self) -> impl Iterator<Item = Self> {
(Self::FIRST.0..=Self::LAST.0).map(Self) (Self::FIRST.0..=Self::LAST.0).map(Self)
} }
@ -195,10 +194,12 @@ impl Rank {
pub const PAWN_DOUBLE_PUSH_TARGET_RANKS: [Rank; 2] = [Rank::FOUR, Rank::FIVE]; pub const PAWN_DOUBLE_PUSH_TARGET_RANKS: [Rank; 2] = [Rank::FOUR, Rank::FIVE];
#[must_use]
pub fn is_pawn_starting_rank(&self, color: Color) -> bool { pub fn is_pawn_starting_rank(&self, color: Color) -> bool {
self == &Self::PAWN_STARTING_RANKS[color as usize] self == &Self::PAWN_STARTING_RANKS[color as usize]
} }
#[must_use]
pub fn is_pawn_double_push_target_rank(&self, color: Color) -> bool { pub fn is_pawn_double_push_target_rank(&self, color: Color) -> bool {
self == &Self::PAWN_DOUBLE_PUSH_TARGET_RANKS[color as usize] self == &Self::PAWN_DOUBLE_PUSH_TARGET_RANKS[color as usize]
} }
@ -220,12 +221,14 @@ impl Square {
/// # Safety /// # Safety
/// ///
/// This function does not do any bounds checking on the input. /// This function does not do any bounds checking on the input.
#[must_use]
pub unsafe fn from_index(x: u8) -> Square { pub unsafe fn from_index(x: u8) -> Square {
debug_assert!((x as usize) < Self::NUM); debug_assert!((x as usize) < Self::NUM);
Self::try_from(x).unwrap_unchecked() Self::try_from(x).unwrap_unchecked()
} }
#[inline] #[inline]
#[must_use]
pub fn from_file_rank(file: File, rank: Rank) -> Square { pub fn from_file_rank(file: File, rank: Rank) -> Square {
let file_int: u8 = file.into(); let file_int: u8 = file.into();
let rank_int: u8 = rank.into(); let rank_int: u8 = rank.into();