1use crate::upscale::UpscaleError;
3use std::fmt;
4
5#[derive(Debug)]
11#[non_exhaustive]
12pub enum ChessError {
13 DimensionMismatch {
15 expected: usize,
17 actual: usize,
19 },
20 Upscale(UpscaleError),
22}
23
24impl fmt::Display for ChessError {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 match self {
27 Self::DimensionMismatch { expected, actual } => write!(
28 f,
29 "image buffer length mismatch: expected {expected} bytes (width*height), got {actual}"
30 ),
31 Self::Upscale(e) => write!(f, "upscale error: {e}"),
32 }
33 }
34}
35
36impl std::error::Error for ChessError {
37 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
38 match self {
39 Self::Upscale(e) => Some(e),
40 _ => None,
41 }
42 }
43}
44
45impl From<UpscaleError> for ChessError {
46 fn from(e: UpscaleError) -> Self {
47 Self::Upscale(e)
48 }
49}