aboutsummaryrefslogtreecommitdiffstats
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs
new file mode 100644
index 0000000..57d636a
--- /dev/null
+++ b/src/error.rs
@@ -0,0 +1,47 @@
+use std::{
+ error,
+ fmt,
+ io,
+};
+
+use utils::NotmuchEnum;
+use ffi;
+
+#[derive(Debug)]
+pub enum Error {
+ IoError(io::Error),
+ NotmuchError(ffi::NotmuchStatus),
+}
+
+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::IoError(ref e) => error::Error::description(e),
+ Error::NotmuchError(ref e) => e.description(),
+ }
+ }
+}
+
+impl error::FromError<io::Error> for Error {
+ fn from_error(err: io::Error) -> Error {
+ Error::IoError(err)
+ }
+}
+
+impl error::FromError<ffi::NotmuchStatus> for Error {
+ fn from_error(err: ffi::NotmuchStatus) -> Error {
+ Error::NotmuchError(err)
+ }
+}
+
+impl error::FromError<ffi::notmuch_status_t> for Error {
+ fn from_error(err: ffi::notmuch_status_t) -> Error {
+ Error::NotmuchError(ffi::NotmuchStatus::from_notmuch_t(err))
+ }
+}