avila_compress/
error.rs

1//! Error types for avila-compress
2
3use std::fmt;
4
5/// Result type for compression operations
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Compression/decompression errors
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub enum Error {
11    /// Input data is invalid or corrupted
12    InvalidInput(String),
13
14    /// Output buffer is too small
15    OutputBufferTooSmall {
16        required: usize,
17        provided: usize,
18    },
19
20    /// Decompression failed due to corrupted data
21    CorruptedData(String),
22
23    /// Unsupported compression level or option
24    UnsupportedOption(String),
25
26    /// Input is too large to compress
27    InputTooLarge {
28        size: usize,
29        max_size: usize,
30    },
31}
32
33impl fmt::Display for Error {
34    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35        match self {
36            Error::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
37            Error::OutputBufferTooSmall { required, provided } => {
38                write!(
39                    f,
40                    "Output buffer too small: need {} bytes, got {}",
41                    required, provided
42                )
43            }
44            Error::CorruptedData(msg) => write!(f, "Corrupted data: {}", msg),
45            Error::UnsupportedOption(msg) => write!(f, "Unsupported option: {}", msg),
46            Error::InputTooLarge { size, max_size } => {
47                write!(f, "Input too large: {} bytes (max: {})", size, max_size)
48            }
49        }
50    }
51}
52
53impl std::error::Error for Error {}