anitty 0.1.0

Anime character animation rendering for terminals
Documentation
use std::{fmt, io};

/// Invalid input, image/terminal encoding failure, or output failure.
#[derive(Debug)]
pub enum Error {
    InvalidFrame(&'static str),
    InvalidSprite(&'static str),
    InvalidRender(&'static str),
    InvalidBackend(&'static str),
    AnimationNotFound(String),
    #[cfg(feature = "spine-38")]
    Spine(String),
    Image(image::ImageError),
    Sixel(icy_sixel::SixelError),
    Io(io::Error),
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::InvalidFrame(message) => write!(f, "invalid RGBA frame: {message}"),
            Self::InvalidSprite(message) => write!(f, "invalid sprite animation: {message}"),
            Self::InvalidRender(message) => write!(f, "invalid render options: {message}"),
            Self::InvalidBackend(message) => write!(f, "invalid terminal backend: {message}"),
            Self::AnimationNotFound(name) => write!(f, "animation not found: {name}"),
            #[cfg(feature = "spine-38")]
            Self::Spine(message) => write!(f, "Spine: {message}"),
            Self::Image(error) => error.fmt(f),
            Self::Sixel(error) => error.fmt(f),
            Self::Io(error) => error.fmt(f),
        }
    }
}

impl std::error::Error for Error {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            Self::Image(error) => Some(error),
            Self::Sixel(error) => Some(error),
            Self::Io(error) => Some(error),
            _ => None,
        }
    }
}

impl From<image::ImageError> for Error {
    fn from(error: image::ImageError) -> Self {
        Self::Image(error)
    }
}

impl From<icy_sixel::SixelError> for Error {
    fn from(error: icy_sixel::SixelError) -> Self {
        Self::Sixel(error)
    }
}

impl From<io::Error> for Error {
    fn from(error: io::Error) -> Self {
        Self::Io(error)
    }
}