1use crate::{
6 coding::{DecodeError, EncodeError},
7 version::Version,
8 Checksum, CompressionType,
9};
10
11#[derive(Debug)]
13#[non_exhaustive]
14pub enum Error {
15 Io(std::io::Error),
17
18 Encode(EncodeError),
20
21 Decode(DecodeError),
23
24 Decompress(CompressionType),
26
27 InvalidVersion(Version),
29
30 Unrecoverable,
32
33 InvalidChecksum((Checksum, Checksum)),
35
36 ValueLog(value_log::Error),
38}
39
40impl std::fmt::Display for Error {
41 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42 write!(f, "LsmTreeError: {self:?}")
43 }
44}
45
46impl std::error::Error for Error {}
47
48impl From<std::io::Error> for Error {
49 fn from(value: std::io::Error) -> Self {
50 Self::Io(value)
51 }
52}
53
54impl From<EncodeError> for Error {
55 fn from(value: EncodeError) -> Self {
56 Self::Encode(value)
57 }
58}
59
60impl From<DecodeError> for Error {
61 fn from(value: DecodeError) -> Self {
62 Self::Decode(value)
63 }
64}
65
66impl From<value_log::Error> for Error {
67 fn from(value: value_log::Error) -> Self {
68 Self::ValueLog(value)
69 }
70}
71
72pub type Result<T> = std::result::Result<T, Error>;