1
0
Fork 0

more public methods

This commit is contained in:
Paul-Nicolas Madelaine 2025-10-19 15:18:30 +02:00
parent 04dfbb23aa
commit 89e6a95ded

View file

@ -127,27 +127,27 @@ impl File {
} }
#[inline] #[inline]
pub fn from_char(c: char) -> Option<Self> { pub fn from_char(file: char) -> Option<Self> {
Self::from_ascii(c as u8) Self::from_ascii(file as u8)
} }
#[inline] #[inline]
pub(crate) fn to_ascii(self) -> u8 { pub fn to_ascii(self) -> u8 {
self as u8 + b'a' self as u8 + b'a'
} }
#[inline] #[inline]
pub(crate) fn from_ascii(c: u8) -> Option<Self> { pub fn from_ascii(file: u8) -> Option<Self> {
(c <= b'h') (file <= b'h')
.then(|| { .then(|| {
c.checked_sub(b'a') file.checked_sub(b'a')
.map(|i| unsafe { Self::new_unchecked(i) }) .map(|i| unsafe { Self::new_unchecked(i) })
}) })
.flatten() .flatten()
} }
#[inline] #[inline]
pub(crate) fn bitboard(self) -> Bitboard { pub fn bitboard(self) -> Bitboard {
Bitboard(0x0101010101010101 << (self as u8)) Bitboard(0x0101010101010101 << (self as u8))
} }
} }
@ -207,8 +207,23 @@ impl Rank {
} }
#[inline] #[inline]
pub fn from_char(c: char) -> Option<Self> { pub fn from_char(rank: char) -> Option<Self> {
Self::from_ascii(c as u8) Self::from_ascii(rank as u8)
}
#[inline]
pub fn to_ascii(self) -> u8 {
self as u8 + b'1'
}
#[inline]
pub fn from_ascii(rank: u8) -> Option<Self> {
(rank <= b'8')
.then(|| {
rank.checked_sub(b'1')
.map(|i| unsafe { Self::new_unchecked(i) })
})
.flatten()
} }
#[inline] #[inline]
@ -217,22 +232,7 @@ impl Rank {
} }
#[inline] #[inline]
pub(crate) fn to_ascii(self) -> u8 { pub fn bitboard(self) -> Bitboard {
self as u8 + b'1'
}
#[inline]
pub(crate) fn from_ascii(c: u8) -> Option<Self> {
(c <= b'8')
.then(|| {
c.checked_sub(b'1')
.map(|i| unsafe { Self::new_unchecked(i) })
})
.flatten()
}
#[inline]
pub(crate) fn bitboard(self) -> Bitboard {
Bitboard(0xFF << ((self as u8) << 3)) Bitboard(0xFF << ((self as u8) << 3))
} }
} }