Skip to main content

marsdb_storage/
error.rs

1use std::fmt;
2
3#[derive(Debug)]
4pub enum StorageError {
5    Database(redb::DatabaseError),
6    Transaction(redb::TransactionError),
7    Table(redb::TableError),
8    Storage(redb::StorageError),
9    Commit(redb::CommitError),
10}
11
12impl fmt::Display for StorageError {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        match self {
15            StorageError::Database(e) => write!(f, "database error: {e}"),
16            StorageError::Transaction(e) => write!(f, "transaction error: {e}"),
17            StorageError::Table(e) => write!(f, "table error: {e}"),
18            StorageError::Storage(e) => write!(f, "storage error: {e}"),
19            StorageError::Commit(e) => write!(f, "commit error: {e}"),
20        }
21    }
22}
23
24impl std::error::Error for StorageError {}
25
26impl From<redb::DatabaseError> for StorageError {
27    fn from(e: redb::DatabaseError) -> Self {
28        StorageError::Database(e)
29    }
30}
31
32impl From<redb::TransactionError> for StorageError {
33    fn from(e: redb::TransactionError) -> Self {
34        StorageError::Transaction(e)
35    }
36}
37
38impl From<redb::TableError> for StorageError {
39    fn from(e: redb::TableError) -> Self {
40        StorageError::Table(e)
41    }
42}
43
44impl From<redb::StorageError> for StorageError {
45    fn from(e: redb::StorageError) -> Self {
46        StorageError::Storage(e)
47    }
48}
49
50impl From<redb::CommitError> for StorageError {
51    fn from(e: redb::CommitError) -> Self {
52        StorageError::Commit(e)
53    }
54}