mod zobrist;
pub use zobrist::Zobrist;
use std::ops::{BitXor, BitXorAssign};
pub const ZOBRIST: Zobrist = Zobrist::new();
#[derive(Copy, Debug, Eq, Hash)]
#[derive_const(Clone, Default, PartialEq)]
#[must_use]
pub struct Key(u64);
impl const From<u64> for Key {
fn from(value: u64) -> Self {
Self(value)
}
}
impl const BitXor for Key {
type Output = Self;
fn bitxor(self, rhs: Self) -> Self::Output {
Self(self.0.bitxor(rhs.0))
}
}
impl const BitXorAssign for Key {
fn bitxor_assign(&mut self, rhs: Self) {
self.0.bitxor_assign(rhs.0);
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn key_clone() {
assert_eq!(Key::default(), Key::default().clone());
}
#[test]
fn key_debug() {
assert_ne!("", format!("{:?}", Key::from(0)));
}
#[test]
fn key_bitxor() {
let k1 = Key::from(0b1010_1111_u64);
let k2 = Key::from(0b1111_1010_u64);
assert_eq!(Key::from(0b0101_0101_u64), k1 ^ k2);
}
#[test]
fn key_bitxor_assign() {
let mut k1 = Key::from(0b1010_1111_u64);
let k2 = Key::from(0b1111_1010_u64);
k1 ^= k2;
assert_eq!(Key::from(0b0101_0101_u64), k1);
}
}