use std::fmt;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
InvalidInput(String),
OutputBufferTooSmall {
required: usize,
provided: usize,
},
CorruptedData(String),
UnsupportedOption(String),
InputTooLarge {
size: usize,
max_size: usize,
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
Error::OutputBufferTooSmall { required, provided } => {
write!(
f,
"Output buffer too small: need {} bytes, got {}",
required, provided
)
}
Error::CorruptedData(msg) => write!(f, "Corrupted data: {}", msg),
Error::UnsupportedOption(msg) => write!(f, "Unsupported option: {}", msg),
Error::InputTooLarge { size, max_size } => {
write!(f, "Input too large: {} bytes (max: {})", size, max_size)
}
}
}
}
impl std::error::Error for Error {}