1use std::fmt;
2
3pub type Result<T> = std::result::Result<T, Error>;
5
6#[derive(Debug)]
8pub enum Error {
9 Database(rusqlite::Error),
11
12 Io(std::io::Error),
14
15 Query(String),
17}
18
19impl fmt::Display for Error {
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 match self {
22 Error::Database(err) => write!(f, "Database error: {}", err),
23 Error::Io(err) => write!(f, "IO error: {}", err),
24 Error::Query(msg) => write!(f, "Query error: {}", msg),
25 }
26 }
27}
28
29impl std::error::Error for Error {
30 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
31 match self {
32 Error::Database(err) => Some(err),
33 Error::Io(err) => Some(err),
34 Error::Query(_) => None,
35 }
36 }
37}
38
39impl From<rusqlite::Error> for Error {
40 fn from(err: rusqlite::Error) -> Self {
41 Error::Database(err)
42 }
43}
44
45impl From<std::io::Error> for Error {
46 fn from(err: std::io::Error) -> Self {
47 Error::Io(err)
48 }
49}