Skip to main content

llkv_btree/
errors.rs

1use core::fmt;
2
3#[derive(Debug, PartialEq, Eq)]
4pub enum Error {
5    Corrupt(&'static str),
6    MissingPage,
7    Pager(&'static str),
8    Invalid(&'static str),
9    KeyNotFound,
10}
11
12impl fmt::Display for Error {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        match self {
15            Error::Corrupt(msg) => write!(f, "corrupt: {msg}"),
16            Error::MissingPage => write!(f, "missing page"),
17            Error::Pager(msg) => write!(f, "pager error: {msg}"),
18            Error::Invalid(msg) => write!(f, "invalid: {msg}"),
19            Error::KeyNotFound => write!(f, "key not found"),
20        }
21    }
22}
23
24impl std::error::Error for Error {}
25
26impl From<std::io::Error> for Error {
27    fn from(_: std::io::Error) -> Self {
28        Error::Pager("io")
29    }
30}