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::key_buckets::BucketError),
25
26 DbCopy(crate::dbcopy::DbCopyError),
28
29 InvalidInput(String),
31
32 TransactionFailed(String),
34}
35
36impl From<crate::partition::PartitionError> for Error {
37 fn from(err: crate::partition::PartitionError) -> Self {
38 Error::Partition(err)
39 }
40}
41
42impl From<crate::roaring::RoaringError> for Error {
43 fn from(err: crate::roaring::RoaringError) -> Self {
44 Error::Roaring(err)
45 }
46}
47
48impl From<crate::key_buckets::BucketError> for Error {
49 fn from(err: crate::key_buckets::BucketError) -> Self {
50 Error::Bucket(err)
51 }
52}
53
54impl From<crate::dbcopy::DbCopyError> for Error {
55 fn from(err: crate::dbcopy::DbCopyError) -> Self {
56 Error::DbCopy(err)
57 }
58}
59
60impl From<redb::StorageError> for Error {
61 fn from(err: redb::StorageError) -> Self {
62 Error::TransactionFailed(format!("Storage error: {}", err))
63 }
64}
65
66impl std::error::Error for Error {
67 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
68 match self {
69 Error::Partition(err) => err.source(),
70 Error::Roaring(err) => err.source(),
71 Error::Bucket(err) => err.source(),
72 Error::DbCopy(err) => err.source(),
73 Error::InvalidInput(_) => None,
74 Error::TransactionFailed(_) => None,
75 }
76 }
77}
78
79impl fmt::Display for Error {
80 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
81 match self {
82 Error::Partition(err) => write!(f, "Partition error: {}", err),
83 Error::Roaring(err) => write!(f, "Roaring error: {}", err),
84 Error::Bucket(err) => write!(f, "Bucket error: {}", err),
85 Error::DbCopy(err) => write!(f, "Database copy error: {}", err),
86 Error::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
87 Error::TransactionFailed(msg) => write!(f, "Transaction failed: {}", msg),
88 }
89 }
90}