1pub type Result<T> = core::result::Result<T, Error>;
6
7#[derive(Debug, derive_more::Display, derive_more::Error, derive_more::From)]
8pub enum Error {
9 #[display("compression failed: {_0}")]
13 Compress(std::io::Error),
14 #[from(skip)]
17 #[display("xz compression failed: {_0}")]
18 Xz(#[error(not(source))] String),
19 #[from(skip)]
20 #[display("utz_encode built without the `zstd` feature")]
21 ZstdNotCompiled,
22 #[from(skip)]
23 #[display("quant_bits must be 16/24/32 (got {bits})")]
24 QuantBits { bits: u32 },
25 #[from(skip)]
26 #[display("grid_deg must be within 0.1\u{2013}45 (got {deg})")]
27 GridDeg { deg: f64 },
28 #[from(skip)]
29 #[display("density weight floor must be within (0, 1) (got {floor})")]
30 DensityWeightFloor { floor: f64 },
31 #[from(skip)]
35 #[display("{what} ({n}) exceeds format limit {max}")]
36 FormatLimit {
37 what: &'static str,
38 n: usize,
39 max: usize,
40 },
41 #[from(skip)]
42 #[display(
43 "grid {deg}°: {n} unique candidate lists exceed the 15-bit tag space — coarsen the grid"
44 )]
45 GridLists { deg: f64, n: usize },
46 #[from(skip)]
47 #[display(
48 "grid {deg}°: {n} interned list ids overflow the u16 offset table — coarsen the grid"
49 )]
50 GridListIds { deg: f64, n: usize },
51}
52
53macro_rules! ensure {
55 ($cond:expr_2021, $err:expr_2021) => {
56 if !($cond) {
57 return Err($err);
58 }
59 };
60}
61pub(crate) use ensure;