use super::Square;
pub const FILES: [File; 8] = [
File::A,
File::B,
File::C,
File::D,
File::E,
File::F,
File::G,
File::H,
];
#[repr(u8)]
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum File {
A,
B,
C,
D,
E,
F,
G,
H,
}
impl File {
#[inline]
pub const fn of(square: Square) -> Self {
unsafe { Self::from_u8_unchecked(square.as_u8() % 8) }
}
#[inline]
pub const fn to_u8(self) -> u8 {
self as u8
}
#[inline]
pub const fn from_u8(val: u8) -> Option<Self> {
if val > 7 {
return None;
}
unsafe { std::mem::transmute(val) }
}
#[inline]
pub const unsafe fn from_u8_unchecked(val: u8) -> Self {
match Self::from_u8(val) {
Some(file) => file,
None => unsafe { std::hint::unreachable_unchecked() },
}
}
}