[BitBoard] Address a bunch of rust-analyzer suggestions
Add #[must_use] to many methods
This commit is contained in:
parent
14ab669763
commit
480a009e63
1 changed files with 14 additions and 2 deletions
|
@ -12,6 +12,7 @@ pub struct BitBoard(pub(crate) u64);
|
||||||
|
|
||||||
macro_rules! moves_getter {
|
macro_rules! moves_getter {
|
||||||
($getter_name:ident) => {
|
($getter_name:ident) => {
|
||||||
|
#[must_use]
|
||||||
pub fn $getter_name(sq: Square) -> BitBoard {
|
pub fn $getter_name(sq: Square) -> BitBoard {
|
||||||
library::library().$getter_name(sq)
|
library::library().$getter_name(sq)
|
||||||
}
|
}
|
||||||
|
@ -22,32 +23,39 @@ impl BitBoard {
|
||||||
pub const EMPTY: BitBoard = BitBoard(u64::MIN);
|
pub const EMPTY: BitBoard = BitBoard(u64::MIN);
|
||||||
pub const FULL: BitBoard = BitBoard(u64::MAX);
|
pub const FULL: BitBoard = BitBoard(u64::MAX);
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub const fn empty() -> BitBoard {
|
pub const fn empty() -> BitBoard {
|
||||||
BitBoard(0)
|
BitBoard(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub const fn new(bits: u64) -> BitBoard {
|
pub const fn new(bits: u64) -> BitBoard {
|
||||||
BitBoard(bits)
|
BitBoard(bits)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn rank(rank: &u8) -> BitBoard {
|
pub fn rank(rank: &u8) -> BitBoard {
|
||||||
debug_assert!(*rank < 8);
|
debug_assert!(*rank < 8);
|
||||||
library::RANKS[*rank as usize]
|
library::RANKS[*rank as usize]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn file(file: &u8) -> BitBoard {
|
pub fn file(file: &u8) -> BitBoard {
|
||||||
debug_assert!(*file < 8);
|
debug_assert!(*file < 8);
|
||||||
library::FILES[*file as usize]
|
library::FILES[*file as usize]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn ray(sq: Square, dir: Direction) -> &'static BitBoard {
|
pub fn ray(sq: Square, dir: Direction) -> &'static BitBoard {
|
||||||
library::library().ray(sq, dir)
|
library::library().ray(sq, dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn pawn_attacks(sq: Square, color: Color) -> BitBoard {
|
pub fn pawn_attacks(sq: Square, color: Color) -> BitBoard {
|
||||||
library::library().pawn_attacks(sq, color)
|
library::library().pawn_attacks(sq, color)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn pawn_pushes(sq: Square, color: Color) -> BitBoard {
|
pub fn pawn_pushes(sq: Square, color: Color) -> BitBoard {
|
||||||
library::library().pawn_pushes(sq, color)
|
library::library().pawn_pushes(sq, color)
|
||||||
}
|
}
|
||||||
|
@ -58,16 +66,19 @@ impl BitBoard {
|
||||||
moves_getter!(queen_moves);
|
moves_getter!(queen_moves);
|
||||||
moves_getter!(king_moves);
|
moves_getter!(king_moves);
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub const fn kingside(color: Color) -> &'static BitBoard {
|
pub const fn kingside(color: Color) -> &'static BitBoard {
|
||||||
&library::KINGSIDES[color as usize]
|
&library::KINGSIDES[color as usize]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub const fn queenside(color: Color) -> &'static BitBoard {
|
pub const fn queenside(color: Color) -> &'static BitBoard {
|
||||||
&library::QUEENSIDES[color as usize]
|
&library::QUEENSIDES[color as usize]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BitBoard {
|
impl BitBoard {
|
||||||
|
#[must_use]
|
||||||
pub const fn as_bits(&self) -> &u64 {
|
pub const fn as_bits(&self) -> &u64 {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
|
@ -82,6 +93,7 @@ impl BitBoard {
|
||||||
/// assert!(!BitBoard::FULL.is_populated());
|
/// assert!(!BitBoard::FULL.is_populated());
|
||||||
/// assert!(!BitBoard::new(0b1000).is_populated());
|
/// assert!(!BitBoard::new(0b1000).is_populated());
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub const fn is_empty(&self) -> bool {
|
pub const fn is_empty(&self) -> bool {
|
||||||
self.0 == 0
|
self.0 == 0
|
||||||
}
|
}
|
||||||
|
@ -269,7 +281,7 @@ impl fmt::Display for BitBoard {
|
||||||
let binary_ranks = format!("{:064b}", self.0)
|
let binary_ranks = format!("{:064b}", self.0)
|
||||||
.chars()
|
.chars()
|
||||||
.rev()
|
.rev()
|
||||||
.map(|c| String::from(c))
|
.map(String::from)
|
||||||
.collect::<Vec<String>>();
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
let mut ranks_written = 0;
|
let mut ranks_written = 0;
|
||||||
|
@ -279,7 +291,7 @@ impl fmt::Display for BitBoard {
|
||||||
|
|
||||||
ranks_written += 1;
|
ranks_written += 1;
|
||||||
if ranks_written < 8 {
|
if ranks_written < 8 {
|
||||||
write!(f, "\n")?;
|
writeln!(f)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue