Skip to main content

laserstream_core_proto/cuckoo/
error.rs

1//! Cuckoo module errors. `Display`/`Error` are hand-written rather than via `thiserror`
2//! (an optional dep of this crate; the cuckoo module is always compiled).
3
4use {super::constants::MAX_KICKS, std::fmt};
5
6/// `with_capacity` failure: capacity can't be allocated (next-pow2 bucket count overflows, or OOM).
7#[derive(Debug, PartialEq, Eq)]
8pub enum CuckooBuildError {
9    CapacityOverflow,
10}
11
12impl fmt::Display for CuckooBuildError {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        match self {
15            Self::CapacityOverflow => {
16                f.write_str("capacity overflow: requested capacity exceeds maximum")
17            }
18        }
19    }
20}
21
22impl std::error::Error for CuckooBuildError {}
23
24/// `insert` failure: filter full — couldn't relocate a fingerprint after `MAX_KICKS` kicks
25/// (typically under-sized). The inserting type's state is unchanged on error.
26#[derive(Debug, PartialEq, Eq)]
27pub struct TableFullError;
28
29impl fmt::Display for TableFullError {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        write!(f, "cuckoo table full after {MAX_KICKS} kicks")
32    }
33}
34
35impl std::error::Error for TableFullError {}