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    /// Data corruption detected
30    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
63/// A specialized `Result` type for RustLite operations.
64pub type Result<T> = std::result::Result<T, Error>;