1use std::fmt;
7
8pub type Result<T> = std::result::Result<T, Error>;
10
11#[derive(Debug)]
16pub enum Error {
17 Partition(crate::partition::PartitionError),
19
20 Roaring(crate::roaring::RoaringError),
22
23 Bucket(crate::buckets::BucketError),
25
26 InvalidInput(String),
28
29 TransactionFailed(String),
31}
32
33impl From<crate::partition::PartitionError> for Error {
34 fn from(err: crate::partition::PartitionError) -> Self {
35 Error::Partition(err)
36 }
37}
38
39impl From<crate::roaring::RoaringError> for Error {
40 fn from(err: crate::roaring::RoaringError) -> Self {
41 Error::Roaring(err)
42 }
43}
44
45impl From<crate::buckets::BucketError> for Error {
46 fn from(err: crate::buckets::BucketError) -> Self {
47 Error::Bucket(err)
48 }
49}
50
51impl From<redb::StorageError> for Error {
52 fn from(err: redb::StorageError) -> Self {
53 Error::TransactionFailed(format!("Storage error: {}", err))
54 }
55}
56
57impl std::error::Error for Error {
58 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
59 match self {
60 Error::Partition(err) => err.source(),
61 Error::Roaring(err) => err.source(),
62 Error::Bucket(err) => err.source(),
63 Error::InvalidInput(_) => None,
64 Error::TransactionFailed(_) => None,
65 }
66 }
67}
68
69impl fmt::Display for Error {
70 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
71 match self {
72 Error::Partition(err) => write!(f, "Partition error: {}", err),
73 Error::Roaring(err) => write!(f, "Roaring error: {}", err),
74 Error::Bucket(err) => write!(f, "Bucket error: {}", err),
75 Error::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
76 Error::TransactionFailed(msg) => write!(f, "Transaction failed: {}", msg),
77 }
78 }
79}