[explorer, moves, core] Improve error handling in explorer

Implement thiserror::Error for a bunch of error types, and remove string errors
from the implementation of the command handler in explorer.

Clean up parsing of basic types all over the place.

Update Cargo files to include thiserror and anyhow.
This commit is contained in:
Eryn Wells 2025-05-19 14:18:31 -07:00
parent 72eeba84ba
commit 9010f1e9c2
12 changed files with 331 additions and 226 deletions

View file

@ -0,0 +1,28 @@
// Eryn Wells <eryn@erynwells.me>
use super::Piece;
#[derive(Default)]
pub enum PieceDisplayStyle {
#[default]
Unicode,
ASCII,
LongForm,
}
pub struct PieceDisplay {
pub(super) piece: Piece,
pub(super) style: PieceDisplayStyle,
}
impl std::fmt::Display for PieceDisplay {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.style {
PieceDisplayStyle::Unicode => write!(f, "{}", self.piece.to_unicode()),
PieceDisplayStyle::ASCII => write!(f, "{}", self.piece.to_ascii()),
PieceDisplayStyle::LongForm => {
write!(f, "{} {}", self.piece.color.name(), self.piece.shape.name())
}
}
}
}