use core::fmt;
pub type Result<T, E = Error> = core::result::Result<T, E>;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Error {
Overflow,
LeadingZero,
InputTooShort,
NonCanonicalSingleByte,
NonCanonicalSize,
UnexpectedLength,
UnexpectedString,
UnexpectedList,
ListLengthMismatch {
expected: usize,
got: usize,
},
Custom(&'static str),
}
#[cfg(feature = "std")]
impl std::error::Error for Error {}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Overflow => f.write_str("overflow"),
Self::LeadingZero => f.write_str("leading zero"),
Self::InputTooShort => f.write_str("input too short"),
Self::NonCanonicalSingleByte => f.write_str("non-canonical single byte"),
Self::NonCanonicalSize => f.write_str("non-canonical size"),
Self::UnexpectedLength => f.write_str("unexpected length"),
Self::UnexpectedString => f.write_str("unexpected string"),
Self::UnexpectedList => f.write_str("unexpected list"),
Self::ListLengthMismatch { got, expected } => {
write!(f, "unexpected list length (got {got}, expected {expected})")
}
Self::Custom(err) => f.write_str(err),
}
}
}