use core::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
TooShort {
need: usize,
got: usize,
},
UnknownMessageType(u8),
WrongMessageType {
expected: u8,
found: u8,
},
InvalidPack(&'static str),
InvalidAuthPage(&'static str),
OutOfRange(&'static str),
NotRemoteId,
BufferTooSmall {
need: usize,
got: usize,
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::TooShort { need, got } => {
write!(f, "input too short: need {need} bytes, got {got}")
}
Error::UnknownMessageType(t) => write!(f, "unknown Remote ID message type {t:#x}"),
Error::WrongMessageType { expected, found } => {
write!(f, "expected message type {expected:#x}, found {found:#x}")
}
Error::InvalidPack(why) => write!(f, "invalid message pack: {why}"),
Error::InvalidAuthPage(why) => write!(f, "invalid authentication page: {why}"),
Error::OutOfRange(field) => write!(f, "value out of range for {field}"),
Error::NotRemoteId => f.write_str("frame carries no Remote ID payload"),
Error::BufferTooSmall { need, got } => {
write!(f, "output buffer too small: need {need} bytes, got {got}")
}
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for Error {}