use crate::image::Pixel; use std::error::Error; use std::fmt::{Display, Formatter, Result}; #[derive(Debug)] pub struct IncompleteMappingError { pub path: std::path::PathBuf, pub missing_colors: Vec, } impl Display for IncompleteMappingError { fn fmt(&self, f: &mut Formatter<'_>) -> Result { writeln!( f, "`{:?}` is missing entries for the following pixel colors:", self.path )?; for color in self.missing_colors.iter() { writeln!(f, " - {:?}", color)?; } Ok(()) } } impl Error for IncompleteMappingError {} #[derive(Debug)] pub struct ThymeFileStructureError { pub message: String, } impl ThymeFileStructureError { pub fn new(msg: impl Into) -> Self { ThymeFileStructureError { message: msg.into(), } } } impl Display for ThymeFileStructureError { fn fmt(&self, f: &mut Formatter<'_>) -> Result { writeln!(f, "{}", self.message) } } impl Error for ThymeFileStructureError {} #[derive(Debug)] pub enum ThymeFileError { StructureError(ThymeFileStructureError), ZipError(zip::result::ZipError), JsonError(serde_json::Error), } impl Display for ThymeFileError { fn fmt(&self, f: &mut Formatter<'_>) -> Result { match self { ThymeFileError::StructureError(err) => write!(f, "Error parsing file: {}", err), ThymeFileError::ZipError(err) => write!(f, "Error with zip wrapper: {}", err), ThymeFileError::JsonError(err) => write!(f, "Error parsing JSON: {}", err), } } } impl Error for ThymeFileError {} impl From for ThymeFileError { fn from(err: zip::result::ZipError) -> Self { ThymeFileError::ZipError(err) } } impl From for ThymeFileError { fn from(err: serde_json::Error) -> Self { ThymeFileError::JsonError(err) } } impl From for ThymeFileError { fn from(err: ThymeFileStructureError) -> Self { ThymeFileError::StructureError(err) } }