1use std::fmt;
2
3#[derive(Debug)]
5pub enum Error {
6 Io(std::io::Error),
8 InvalidDatabase(String),
10}
11
12impl fmt::Display for Error {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 match self {
15 Error::Io(e) => write!(f, "I/O error: {e}"),
16 Error::InvalidDatabase(msg) => write!(f, "invalid database: {msg}"),
17 }
18 }
19}
20
21impl std::error::Error for Error {
22 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
23 match self {
24 Error::Io(e) => Some(e),
25 Error::InvalidDatabase(_) => None,
26 }
27 }
28}
29
30impl From<std::io::Error> for Error {
31 fn from(e: std::io::Error) -> Self {
32 Error::Io(e)
33 }
34}