1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use std::convert::From;
use std::{error, fmt, io, result};
pub type Result<T> = result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
IoError(io::Error),
JSONError(serde_json::Error),
RegexError(regex::Error),
NotmuchError(notmuch::Error),
MailParseError(mailparse::MailParseError),
UnsupportedQuery(String),
UnsupportedValue(String),
RegexUncompiled(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", error::Error::description(self))
}
}
impl error::Error for Error {
fn description(&self) -> &str {
match self {
Error::UnsupportedQuery(e) => e,
Error::UnsupportedValue(e) => e,
Error::RegexUncompiled(e) => e,
_ => self.description(),
}
}
fn cause(&self) -> Option<&dyn error::Error> {
match self {
_ => Some(self),
}
}
}
impl From<serde_json::Error> for Error {
fn from(s: serde_json::Error) -> Error {
Error::JSONError(s)
}
}
impl From<io::Error> for Error {
fn from(s: std::io::Error) -> Error {
Error::IoError(s)
}
}
impl From<regex::Error> for Error {
fn from(s: regex::Error) -> Error {
Error::RegexError(s)
}
}
impl From<notmuch::Error> for Error {
fn from(s: notmuch::Error) -> Error {
Error::NotmuchError(s)
}
}
impl From<mailparse::MailParseError> for Error {
fn from(s: mailparse::MailParseError) -> Error {
Error::MailParseError(s)
}
}