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.
28 lines
725 B
Rust
28 lines
725 B
Rust
// 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())
|
|
}
|
|
}
|
|
}
|
|
}
|