rustlite_core/
error.rs

1//! Error types for RustLite.
2
3use std::fmt;
4
5/// The main error type for RustLite operations.
6#[derive(Debug)]
7pub enum Error {
8    /// A lock was poisoned (internal error)
9    LockPoisoned,
10
11    /// I/O error
12    Io(std::io::Error),
13
14    /// Serialization/deserialization error
15    Serialization(String),
16
17    /// Storage engine error
18    Storage(String),
19
20    /// Transaction error
21    Transaction(String),
22
23    /// Invalid operation
24    InvalidOperation(String),
25
26    /// Not found
27    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
59/// A specialized `Result` type for RustLite operations.
60pub type Result<T> = std::result::Result<T, Error>;