pixie_anim_lib/
error.rs

1//! Error handling.
2
3use std::fmt;
4
5/// Result type for Pixie-Anim operations.
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Error types for Pixie-Anim.
9#[derive(Debug)]
10pub enum Error {
11    /// Standard IO error.
12    Io(std::io::Error),
13    /// Error related to GIF structure.
14    InvalidGif(String),
15    /// Error during LZW encoding.
16    LzwError(String),
17    /// Error during color quantization.
18    QuantizationError(String),
19    /// Internal or unexpected error.
20    Internal(String),
21}
22
23impl fmt::Display for Error {
24    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25        match self {
26            Error::Io(e) => write!(f, "IO error: {}", e),
27            Error::InvalidGif(s) => write!(f, "Invalid GIF: {}", s),
28            Error::LzwError(s) => write!(f, "LZW error: {}", s),
29            Error::QuantizationError(s) => write!(f, "Quantization error: {}", s),
30            Error::Internal(s) => write!(f, "Internal error: {}", s),
31        }
32    }
33}
34
35impl std::error::Error for Error {}
36
37impl From<std::io::Error> for Error {
38    fn from(err: std::io::Error) -> Self {
39        Error::Io(err)
40    }
41}