use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum FormatError {
BadMagic,
UnsupportedVersion(u8),
UnknownFlags(u8),
NonZeroReserved,
Truncated,
TrailingBytes,
LimitExceeded(&'static str),
InvalidUtf8,
Invalid(&'static str),
}
impl fmt::Display for FormatError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::BadMagic => f.write_str("wrong magic"),
Self::UnsupportedVersion(v) => write!(f, "unsupported version {v}"),
Self::UnknownFlags(v) => write!(f, "unknown flag bits {v:#04x}"),
Self::NonZeroReserved => f.write_str("reserved field is not zero"),
Self::Truncated => f.write_str("truncated input"),
Self::TrailingBytes => f.write_str("trailing bytes"),
Self::LimitExceeded(what) => write!(f, "limit exceeded: {what}"),
Self::InvalidUtf8 => f.write_str("string is not valid UTF-8"),
Self::Invalid(what) => write!(f, "invalid: {what}"),
}
}
}
impl std::error::Error for FormatError {}
pub type Result<T> = std::result::Result<T, FormatError>;