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
|
use std;
use std::{fmt, io, result};
use ffi;
pub type Result<T> = result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
IoError(io::Error),
NotmuchError(ffi::Status),
UnspecifiedError,
}
impl std::error::Error for Error {}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::IoError(e) => write!(f, "IO error: {}", e),
Error::NotmuchError(e) => write!(f, "notmuch error: {}", e),
Error::UnspecifiedError => write!(f, "unspecified error"),
}
}
}
impl std::convert::From<io::Error> for Error {
fn from(err: io::Error) -> Error {
Error::IoError(err)
}
}
impl std::convert::From<ffi::Status> for Error {
fn from(err: ffi::Status) -> Error {
Error::NotmuchError(err)
}
}
impl std::convert::From<ffi::notmuch_status_t> for Error {
fn from(err: ffi::notmuch_status_t) -> Error {
Error::NotmuchError(ffi::Status::from(err))
}
}
|