use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Error {
BadArg(&'static str),
BufferTooSmall(&'static str),
InvalidPacket(&'static str),
Internal(&'static str),
}
impl Error {
#[must_use]
pub const fn code(&self) -> i32 {
match self {
Self::BadArg(_) => -1,
Self::BufferTooSmall(_) => -2,
Self::Internal(_) => -3,
Self::InvalidPacket(_) => -4,
}
}
#[must_use]
pub const fn message(&self) -> &'static str {
match self {
Self::BadArg(m)
| Self::BufferTooSmall(m)
| Self::InvalidPacket(m)
| Self::Internal(m) => m,
}
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.message())
}
}
impl std::error::Error for Error {}