use core::fmt;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[non_exhaustive]
pub enum CompressionErrorKind {
InvalidMagic,
UnsupportedVersion,
ChecksumMismatch,
Truncated,
InvalidFormat,
UnsupportedEndianPolicy,
MissingBody,
MissingChannel,
OutOfRangeInstant,
UnsupportedTimeScale,
QuantizationOverflow,
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CompressionError {
pub kind: CompressionErrorKind,
pub message: String,
}
impl CompressionError {
pub fn new(kind: CompressionErrorKind, message: impl Into<String>) -> Self {
Self {
kind,
message: message.into(),
}
}
}
impl fmt::Display for CompressionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}: {}", self.kind, self.message)
}
}
impl std::error::Error for CompressionError {}