use core::error::Error as BaseError;
use core::fmt::{Display, Formatter, Result as FmtResult};
#[derive(Debug)]
pub enum Error {
LengthOverflow {
max: usize,
actual: usize,
},
UnexpectedEof {
needed: usize,
remaining: usize,
},
Malformed(
&'static str,
),
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
match self {
Self::LengthOverflow { max, actual } => {
write!(f, "length exceeds maximum: {actual} > {max}")
}
Self::UnexpectedEof { needed, remaining } => {
write!(
f,
"unexpected end of data: needed {needed} bytes, but only {remaining} remain"
)
}
Self::Malformed(message) => {
write!(f, "malformed data: {message}")
}
}
}
}
impl BaseError for Error {}