[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:
parent
72eeba84ba
commit
9010f1e9c2
12 changed files with 331 additions and 226 deletions
28
core/src/pieces/display.rs
Normal file
28
core/src/pieces/display.rs
Normal 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())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue