1use std::fmt;
4
5#[derive(Debug)]
7pub enum Error {
8 LockPoisoned,
10
11 Io(std::io::Error),
13
14 Serialization(String),
16
17 Storage(String),
19
20 Transaction(String),
22
23 InvalidOperation(String),
25
26 NotFound,
28
29 Corruption(String),
31}
32
33impl fmt::Display for Error {
34 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35 match self {
36 Error::LockPoisoned => write!(f, "Lock poisoned"),
37 Error::Io(e) => write!(f, "I/O error: {}", e),
38 Error::Serialization(msg) => write!(f, "Serialization error: {}", msg),
39 Error::Storage(msg) => write!(f, "Storage error: {}", msg),
40 Error::Transaction(msg) => write!(f, "Transaction error: {}", msg),
41 Error::InvalidOperation(msg) => write!(f, "Invalid operation: {}", msg),
42 Error::NotFound => write!(f, "Not found"),
43 Error::Corruption(msg) => write!(f, "Data corruption: {}", msg),
44 }
45 }
46}
47
48impl std::error::Error for Error {
49 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
50 match self {
51 Error::Io(e) => Some(e),
52 _ => None,
53 }
54 }
55}
56
57impl From<std::io::Error> for Error {
58 fn from(err: std::io::Error) -> Self {
59 Error::Io(err)
60 }
61}
62
63pub type Result<T> = std::result::Result<T, Error>;