use crate::upscale::UpscaleError;
use std::fmt;
#[derive(Debug)]
#[non_exhaustive]
pub enum ChessError {
DimensionMismatch {
expected: usize,
actual: usize,
},
Upscale(UpscaleError),
}
impl fmt::Display for ChessError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::DimensionMismatch { expected, actual } => write!(
f,
"image buffer length mismatch: expected {expected} bytes (width*height), got {actual}"
),
Self::Upscale(e) => write!(f, "upscale error: {e}"),
}
}
}
impl std::error::Error for ChessError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Upscale(e) => Some(e),
_ => None,
}
}
}
impl From<UpscaleError> for ChessError {
fn from(e: UpscaleError) -> Self {
Self::Upscale(e)
}
}