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
30impl fmt::Display for Error {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 match self {
33 Error::LockPoisoned => write!(f, "Lock poisoned"),
34 Error::Io(e) => write!(f, "I/O error: {}", e),
35 Error::Serialization(msg) => write!(f, "Serialization error: {}", msg),
36 Error::Storage(msg) => write!(f, "Storage error: {}", msg),
37 Error::Transaction(msg) => write!(f, "Transaction error: {}", msg),
38 Error::InvalidOperation(msg) => write!(f, "Invalid operation: {}", msg),
39 Error::NotFound => write!(f, "Not found"),
40 }
41 }
42}
43
44impl std::error::Error for Error {
45 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
46 match self {
47 Error::Io(e) => Some(e),
48 _ => None,
49 }
50 }
51}
52
53impl From<std::io::Error> for Error {
54 fn from(err: std::io::Error) -> Self {
55 Error::Io(err)
56 }
57}
58
59pub type Result<T> = std::result::Result<T, Error>;