1
0
Fork 0

update interface for text records

This commit is contained in:
Paul-Nicolas Madelaine 2025-10-23 23:34:31 +02:00
parent 0d8b9cc9cf
commit 149aa841c9
5 changed files with 198 additions and 179 deletions

View file

@ -82,16 +82,28 @@ impl Position {
/// ```
/// # use eschac::setup::Setup;
/// # |s: &str| -> Option<eschac::position::Position> {
/// s.parse::<Setup>().ok().and_then(|pos| pos.into_position().ok())
/// Setup::from_text_record(s).ok().and_then(|pos| pos.into_position().ok())
/// # };
/// ```
#[inline]
pub fn from_text_record(s: &str) -> Option<Self> {
s.parse::<Setup>()
Setup::from_text_record(s)
.ok()
.and_then(|pos| pos.into_position().ok())
}
/// Returns the text record of the position.
///
/// This is a shortcut for:
/// ```
/// # |position: eschac::position::Position| {
/// position.as_setup().to_text_record()
/// # };
#[inline]
pub fn to_text_record(&self) -> String {
self.as_setup().to_text_record()
}
/// Returns all the legal moves on the position.
#[inline]
pub fn legal_moves<'l>(&'l self) -> Moves<'l> {
@ -469,7 +481,7 @@ impl Position {
impl std::fmt::Debug for Position {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
f.debug_tuple("Position")
.field(&self.as_setup().to_string())
.field(&TextRecord(self.as_setup()))
.finish()
}
}