no_std
This commit is contained in:
parent
c0e915f1b4
commit
00261d95c1
9 changed files with 102 additions and 96 deletions
44
src/setup.rs
44
src/setup.rs
|
|
@ -7,6 +7,8 @@ use crate::board::*;
|
|||
use crate::lookup;
|
||||
use crate::position::*;
|
||||
|
||||
use alloc::string::String;
|
||||
|
||||
/// **A builder type for chess positions.**
|
||||
///
|
||||
/// This type is useful to edit a position without having to ensure it stays legal at every step.
|
||||
|
|
@ -152,9 +154,9 @@ impl Setup {
|
|||
}
|
||||
|
||||
/// Writes the text record of the position.
|
||||
pub fn write_text_record<W>(&self, w: &mut W) -> std::fmt::Result
|
||||
pub fn write_text_record<W>(&self, w: &mut W) -> core::fmt::Result
|
||||
where
|
||||
W: std::fmt::Write,
|
||||
W: core::fmt::Write,
|
||||
{
|
||||
for rank in Rank::all().into_iter().rev() {
|
||||
let mut count = 0;
|
||||
|
|
@ -526,14 +528,14 @@ impl TryFrom<Setup> for Position {
|
|||
}
|
||||
|
||||
pub(crate) struct TextRecord<'a>(pub(crate) &'a Setup);
|
||||
impl<'a> std::fmt::Display for TextRecord<'a> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
impl<'a> core::fmt::Display for TextRecord<'a> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
self.0.write_text_record(f)
|
||||
}
|
||||
}
|
||||
impl<'a> std::fmt::Debug for TextRecord<'a> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
use std::fmt::Write;
|
||||
impl<'a> core::fmt::Debug for TextRecord<'a> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
use core::fmt::Write;
|
||||
f.write_char('"')?;
|
||||
self.0.write_text_record(f)?;
|
||||
f.write_char('"')?;
|
||||
|
|
@ -541,8 +543,8 @@ impl<'a> std::fmt::Debug for TextRecord<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Setup {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
impl core::fmt::Debug for Setup {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
|
||||
f.debug_tuple("Setup").field(&TextRecord(&self)).finish()
|
||||
}
|
||||
}
|
||||
|
|
@ -555,9 +557,9 @@ pub struct IllegalPosition {
|
|||
pub setup: Setup,
|
||||
pub reasons: IllegalPositionReasons,
|
||||
}
|
||||
impl std::fmt::Display for IllegalPosition {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
use std::fmt::Write;
|
||||
impl core::fmt::Display for IllegalPosition {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
use core::fmt::Write;
|
||||
let setup = &self.setup;
|
||||
write!(f, "`{}` is illegal:", &TextRecord(setup))?;
|
||||
let mut first = true;
|
||||
|
|
@ -572,14 +574,14 @@ impl std::fmt::Display for IllegalPosition {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
impl std::error::Error for IllegalPosition {}
|
||||
impl core::error::Error for IllegalPosition {}
|
||||
|
||||
/// A set of [`IllegalPositionReason`]s.
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct IllegalPositionReasons(u8);
|
||||
|
||||
impl std::fmt::Debug for IllegalPositionReasons {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
impl core::fmt::Debug for IllegalPositionReasons {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
f.debug_list().entries(*self).finish()
|
||||
}
|
||||
}
|
||||
|
|
@ -607,7 +609,7 @@ impl Iterator for IllegalPositionReasons {
|
|||
} else {
|
||||
let reason = 1 << self.0.trailing_zeros();
|
||||
self.0 &= !reason;
|
||||
Some(unsafe { std::mem::transmute::<u8, IllegalPositionReason>(reason) })
|
||||
Some(unsafe { core::mem::transmute::<u8, IllegalPositionReason>(reason) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -659,8 +661,8 @@ impl IllegalPositionReason {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for IllegalPositionReason {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
impl core::fmt::Display for IllegalPositionReason {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
f.write_str(self.to_str())
|
||||
}
|
||||
}
|
||||
|
|
@ -670,9 +672,9 @@ impl std::fmt::Display for IllegalPositionReason {
|
|||
pub struct ParseRecordError {
|
||||
pub byte: usize,
|
||||
}
|
||||
impl std::fmt::Display for ParseRecordError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
impl core::fmt::Display for ParseRecordError {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
write!(f, "invalid text record (at byte {})", self.byte)
|
||||
}
|
||||
}
|
||||
impl std::error::Error for ParseRecordError {}
|
||||
impl core::error::Error for ParseRecordError {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue