append_log/
error.rs

1use std::error::Error as StdError;
2use std::fmt;
3use std::io;
4
5#[derive(Debug)]
6pub enum Error {
7    InvalidLength,
8    InvalidMagic,
9    InvalidChecksum,
10    NotImplemented,
11    IO(io::Error),
12}
13
14impl StdError for Error {
15    fn description(&self) -> &str {
16        match self {
17            Error::InvalidLength => "Log file length is not a multiple of block size",
18            Error::InvalidMagic => "Invalid magic value at the end of the log file",
19            Error::InvalidChecksum => "Checksum mismatch during read",
20            Error::NotImplemented => "Feature is not implemented yet",
21            Error::IO(_) => "IO error",
22        }
23    }
24}
25
26impl fmt::Display for Error {
27    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
28        match self {
29            Error::IO(err) => write!(f, "IO error: {}", err),
30            _ => write!(f, "{}", self.description()),
31        }
32    }
33}
34
35impl From<io::Error> for Error {
36    fn from(err: io::Error) -> Self {
37        Error::IO(err)
38    }
39}