use core::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum HllError {
PrecisionMismatch { left: u32, right: u32 },
InvalidPrecision(u32),
BadMagic,
UnsupportedVersion(u8),
UnsupportedEncoding(u8),
Truncated { expected: usize, actual: usize },
}
impl fmt::Display for HllError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
HllError::PrecisionMismatch { left, right } => {
write!(f, "precision mismatch: {left} vs {right}")
}
HllError::InvalidPrecision(p) => write!(f, "precision {p} outside [4, 18]"),
HllError::BadMagic => write!(f, "bad magic: not a subms-hyperloglog buffer"),
HllError::UnsupportedVersion(v) => write!(f, "unsupported format version {v}"),
HllError::UnsupportedEncoding(e) => write!(f, "unsupported encoding {e}"),
HllError::Truncated { expected, actual } => {
write!(
f,
"truncated buffer: expected {expected} bytes, got {actual}"
)
}
}
}
}
impl std::error::Error for HllError {}
#[cfg(test)]
#[path = "error_tests.rs"]
mod tests;