subms_hyperloglog/
error.rs1use core::fmt;
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11#[non_exhaustive]
12pub enum HllError {
13 PrecisionMismatch { left: u32, right: u32 },
16 InvalidPrecision(u32),
18 BadMagic,
20 UnsupportedVersion(u8),
22 UnsupportedEncoding(u8),
25 Truncated { expected: usize, actual: usize },
27}
28
29impl fmt::Display for HllError {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 match self {
32 HllError::PrecisionMismatch { left, right } => {
33 write!(f, "precision mismatch: {left} vs {right}")
34 }
35 HllError::InvalidPrecision(p) => write!(f, "precision {p} outside [4, 18]"),
36 HllError::BadMagic => write!(f, "bad magic: not a subms-hyperloglog buffer"),
37 HllError::UnsupportedVersion(v) => write!(f, "unsupported format version {v}"),
38 HllError::UnsupportedEncoding(e) => write!(f, "unsupported encoding {e}"),
39 HllError::Truncated { expected, actual } => {
40 write!(
41 f,
42 "truncated buffer: expected {expected} bytes, got {actual}"
43 )
44 }
45 }
46 }
47}
48
49impl std::error::Error for HllError {}
50
51#[cfg(test)]
52#[path = "error_tests.rs"]
53mod tests;