use std::error::Error as StdError;
use std::fmt::{Display, Formatter};
#[derive(Debug)]
pub enum Error {
Io(std::io::Error),
Image(image::ImageError),
SerdeJson(serde_json::Error),
Message(String),
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::Io(error) => write!(f, "I/O error: {error}"),
Self::Image(error) => write!(f, "image error: {error}"),
Self::SerdeJson(error) => write!(f, "serde_json error: {error}"),
Self::Message(message) => f.write_str(message),
}
}
}
impl StdError for Error {}
impl From<std::io::Error> for Error {
fn from(value: std::io::Error) -> Self {
Self::Io(value)
}
}
impl From<image::ImageError> for Error {
fn from(value: image::ImageError) -> Self {
Self::Image(value)
}
}
impl From<serde_json::Error> for Error {
fn from(value: serde_json::Error) -> Self {
Self::SerdeJson(value)
}
}
pub type Result<T> = std::result::Result<T, Error>;