#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
pub enum Error {
#[non_exhaustive]
InvalidChar {
index: usize,
byte: u8,
},
#[non_exhaustive]
OutputTooSmall {
required: usize,
},
#[non_exhaustive]
LengthMismatch {
expected: usize,
actual: usize,
},
OddLength,
Overflow,
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match *self {
Self::InvalidChar { index, byte } => {
write!(f, "invalid hex byte 0x{byte:02x} at index {index}")
}
Self::OutputTooSmall { required } => {
write!(f, "output requires at least {required} bytes")
}
Self::LengthMismatch { expected, actual } => {
write!(f, "expected {expected} decoded bytes, got {actual}")
}
Self::OddLength => f.write_str("hex input length must be even"),
Self::Overflow => f.write_str("encoded length overflow"),
}
}
}
impl core::error::Error for Error {}