redb_extras/key_buckets/
mod.rs

1//! Bucketed storage utility module.
2//!
3//! This module provides bucket-based key grouping for sequence data.
4//! It enables range queries by organizing sequences into deterministic
5//! buckets using configurable bucket sizes.
6//!
7//! Public bucket iterators perform per-bucket point lookups, so `bucket_range`
8//! scans only the buckets in the requested sequence range without filtering
9//! through unrelated base keys.
10
11use std::fmt;
12
13/// Errors specific to the bucket layer.
14#[derive(Debug)]
15pub enum BucketError {
16    /// Invalid bucket size configuration
17    InvalidBucketSize(u64),
18
19    /// Invalid bucket range for iteration
20    InvalidRange { start: u64, end: u64 },
21
22    /// Serialization operation failed
23    SerializationError(String),
24
25    /// Iteration over bucket range failed
26    IterationError(String),
27}
28
29impl fmt::Display for BucketError {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        match self {
32            BucketError::InvalidBucketSize(size) => {
33                write!(f, "Invalid bucket size {}: must be greater than 0", size)
34            }
35            BucketError::InvalidRange { start, end } => {
36                write!(
37                    f,
38                    "Invalid bucket range: start {} must be <= end {}",
39                    start, end
40                )
41            }
42            BucketError::SerializationError(msg) => {
43                write!(f, "Serialization error: {}", msg)
44            }
45            BucketError::IterationError(msg) => {
46                write!(f, "Bucket iteration error: {}", msg)
47            }
48        }
49    }
50}
51
52impl std::error::Error for BucketError {
53    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
54        None
55    }
56}
57
58pub mod iterator;
59pub mod key;
60
61// Re-export main types for public API
62pub use iterator::{
63    BucketIterExt, BucketMultimapIterExt, BucketRangeIterator, BucketRangeMultimapIterator,
64};
65pub use key::{BucketedKey, KeyBuilder};