[BitBoard] Address a bunch of rust-analyzer suggestions

Add #[must_use] to many methods
This commit is contained in:
Eryn Wells 2024-07-13 07:17:43 -07:00
parent 14ab669763
commit 480a009e63

View file

@ -12,6 +12,7 @@ pub struct BitBoard(pub(crate) u64);
macro_rules! moves_getter {
($getter_name:ident) => {
#[must_use]
pub fn $getter_name(sq: Square) -> BitBoard {
library::library().$getter_name(sq)
}
@ -22,32 +23,39 @@ impl BitBoard {
pub const EMPTY: BitBoard = BitBoard(u64::MIN);
pub const FULL: BitBoard = BitBoard(u64::MAX);
#[must_use]
pub const fn empty() -> BitBoard {
BitBoard(0)
}
#[must_use]
pub const fn new(bits: u64) -> BitBoard {
BitBoard(bits)
}
#[must_use]
pub fn rank(rank: &u8) -> BitBoard {
debug_assert!(*rank < 8);
library::RANKS[*rank as usize]
}
#[must_use]
pub fn file(file: &u8) -> BitBoard {
debug_assert!(*file < 8);
library::FILES[*file as usize]
}
#[must_use]
pub fn ray(sq: Square, dir: Direction) -> &'static BitBoard {
library::library().ray(sq, dir)
}
#[must_use]
pub fn pawn_attacks(sq: Square, color: Color) -> BitBoard {
library::library().pawn_attacks(sq, color)
}
#[must_use]
pub fn pawn_pushes(sq: Square, color: Color) -> BitBoard {
library::library().pawn_pushes(sq, color)
}
@ -58,16 +66,19 @@ impl BitBoard {
moves_getter!(queen_moves);
moves_getter!(king_moves);
#[must_use]
pub const fn kingside(color: Color) -> &'static BitBoard {
&library::KINGSIDES[color as usize]
}
#[must_use]
pub const fn queenside(color: Color) -> &'static BitBoard {
&library::QUEENSIDES[color as usize]
}
}
impl BitBoard {
#[must_use]
pub const fn as_bits(&self) -> &u64 {
&self.0
}
@ -82,6 +93,7 @@ impl BitBoard {
/// assert!(!BitBoard::FULL.is_populated());
/// assert!(!BitBoard::new(0b1000).is_populated());
/// ```
#[must_use]
pub const fn is_empty(&self) -> bool {
self.0 == 0
}
@ -269,7 +281,7 @@ impl fmt::Display for BitBoard {
let binary_ranks = format!("{:064b}", self.0)
.chars()
.rev()
.map(|c| String::from(c))
.map(String::from)
.collect::<Vec<String>>();
let mut ranks_written = 0;
@ -279,7 +291,7 @@ impl fmt::Display for BitBoard {
ranks_written += 1;
if ranks_written < 8 {
write!(f, "\n")?;
writeln!(f)?;
}
}