Statically assert zero-cost invariants
Since some or all of those invariants will come in handy to ensure we use as little memory as possible, to maximize the speed of the move generation later on.
This commit is contained in:
parent
d51d72377e
commit
585c127381
|
@ -1,4 +1,6 @@
|
|||
use super::Square;
|
||||
use crate::utils::static_assert;
|
||||
|
||||
mod iterator;
|
||||
use iterator::*;
|
||||
|
||||
|
@ -63,6 +65,9 @@ impl Bitboard {
|
|||
}
|
||||
}
|
||||
|
||||
// Ensure zero-cost (at least size-wise) wrapping.
|
||||
static_assert!(std::mem::size_of::<Bitboard>() == std::mem::size_of::<u64>());
|
||||
|
||||
impl Default for Bitboard {
|
||||
fn default() -> Self {
|
||||
Self::EMPTY
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use super::Bitboard;
|
||||
use crate::utils::static_assert;
|
||||
|
||||
/// An enum representing a singular file on a chess board (i.e: the columns).
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
|
@ -74,6 +75,9 @@ impl File {
|
|||
}
|
||||
}
|
||||
|
||||
// Ensure that niche-optimization is in effect.
|
||||
static_assert!(std::mem::size_of::<Option<File>>() == std::mem::size_of::<File>());
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use super::Bitboard;
|
||||
use crate::utils::static_assert;
|
||||
|
||||
/// An enum representing a singular rank on a chess board (i.e: the rows).
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
|
@ -74,6 +75,9 @@ impl Rank {
|
|||
}
|
||||
}
|
||||
|
||||
// Ensure that niche-optimization is in effect.
|
||||
static_assert!(std::mem::size_of::<Option<Rank>>() == std::mem::size_of::<Rank>());
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use super::{Bitboard, File, Rank};
|
||||
use crate::utils::static_assert;
|
||||
|
||||
/// Represent a square on a chessboard. Defined in the same order as the
|
||||
/// [Bitboard](crate::board::Bitboard) squares.
|
||||
|
@ -185,6 +186,9 @@ impl std::ops::Sub<Bitboard> for Square {
|
|||
}
|
||||
}
|
||||
|
||||
// Ensure that niche-optimization is in effect.
|
||||
static_assert!(std::mem::size_of::<Option<Square>>() == std::mem::size_of::<Square>());
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
|
Loading…
Reference in a new issue