#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Error {
Unsupported,
BufferTooSmall {
needed: usize,
},
InvalidGeometry,
InvalidFormat,
Hardware,
Timeout,
Busy,
Crypto,
Denied,
Corrupt,
}
impl Error {
#[must_use]
pub const fn code(self) -> &'static str {
match self {
Error::Unsupported => "unsupported",
Error::BufferTooSmall { .. } => "buffer_too_small",
Error::InvalidGeometry => "invalid_geometry",
Error::InvalidFormat => "invalid_format",
Error::Hardware => "hardware",
Error::Timeout => "timeout",
Error::Busy => "busy",
Error::Crypto => "crypto",
Error::Denied => "denied",
Error::Corrupt => "corrupt",
}
}
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Error::BufferTooSmall { needed } => write!(f, "buffer too small: need {needed} bytes"),
other => f.write_str(other.code()),
}
}
}
impl core::error::Error for Error {}
pub type Result<T, E = Error> = core::result::Result<T, E>;