use core::fmt;
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Error {
UnexpectedEof,
BufferFull,
VarintOverflow,
FrameTooLarge {
len: usize,
limit: usize,
},
InvalidLengthPrefix,
DelimiterNotFound,
InvalidEncoding,
BitOverflow,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Error::UnexpectedEof => f.write_str("unexpected end of input"),
Error::BufferFull => f.write_str("output buffer is full"),
Error::VarintOverflow => f.write_str("varint encoded length exceeded the target width"),
Error::FrameTooLarge { len, limit } => {
write!(f, "frame length {len} exceeds configured limit {limit}")
}
Error::InvalidLengthPrefix => f.write_str("length prefix is structurally invalid"),
Error::DelimiterNotFound => f.write_str("delimiter not found in input"),
Error::InvalidEncoding => f.write_str("encoded data violates a structural invariant"),
Error::BitOverflow => f.write_str("bit width or value out of range"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for Error {}
pub type Result<T> = core::result::Result<T, Error>;