diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-05-15 16:53:31 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-05-17 00:26:36 +0200 |
commit | c730cce83baeb49cb90346456ccc2a09db675d75 (patch) | |
tree | 33580231c33edeecf06726dde4d646f95b524e62 /libimagnotes | |
parent | 841d26fdd0c848359a23e3bd73b72ab73f32d868 (diff) |
libimagnotes: Replace error code with code generator macro
Diffstat (limited to 'libimagnotes')
-rw-r--r-- | libimagnotes/Cargo.toml | 3 | ||||
-rw-r--r-- | libimagnotes/src/error.rs | 86 | ||||
-rw-r--r-- | libimagnotes/src/lib.rs | 1 |
3 files changed, 10 insertions, 80 deletions
diff --git a/libimagnotes/Cargo.toml b/libimagnotes/Cargo.toml index 6bc99cee..f13cf218 100644 --- a/libimagnotes/Cargo.toml +++ b/libimagnotes/Cargo.toml @@ -11,6 +11,9 @@ toml = "0.1.25" [dependencies.libimagstore] path = "../libimagstore" +[dependencies.libimagerror] +path = "../libimagerror" + [dependencies.libimagrt] path = "../libimagrt" diff --git a/libimagnotes/src/error.rs b/libimagnotes/src/error.rs index ec1f5535..527aa710 100644 --- a/libimagnotes/src/error.rs +++ b/libimagnotes/src/error.rs @@ -2,84 +2,10 @@ use std::error::Error; use std::fmt::Error as FmtError; use std::fmt::{Display, Formatter}; -/** - * Kind of error - */ -#[derive(Clone, Copy, Debug, PartialEq)] -pub enum NoteErrorKind { - StoreWriteError, - StoreReadError, - HeaderTypeError, - NoteToEntryConversion, - // Nothing here yet -} - -fn note_error_type_as_str(e: &NoteErrorKind) -> &'static str { - match *e { - NoteErrorKind::StoreWriteError => "Error writing store", - NoteErrorKind::StoreReadError => "Error reading store", - NoteErrorKind::HeaderTypeError => "Header type error", - NoteErrorKind::NoteToEntryConversion => "Error converting Note instance to Entry instance", - } -} - -impl Display for NoteErrorKind { - - fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { - try!(write!(fmt, "{}", note_error_type_as_str(self))); - Ok(()) - } - -} - -/** - * Store error type - */ -#[derive(Debug)] -pub struct NoteError { - err_type: NoteErrorKind, - cause: Option<Box<Error>>, -} - -impl NoteError { - - /** - * Build a new NoteError from an NoteErrorKind, optionally with cause - */ - pub fn new(errtype: NoteErrorKind, cause: Option<Box<Error>>) -> NoteError { - NoteError { - err_type: errtype, - cause: cause, - } - } - - /** - * Get the error type of this NoteError - */ - pub fn err_type(&self) -> NoteErrorKind { - self.err_type - } - -} - -impl Display for NoteError { - - fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { - try!(write!(fmt, "[{}]", note_error_type_as_str(&self.err_type))); - Ok(()) - } - -} - -impl Error for NoteError { - - fn description(&self) -> &str { - note_error_type_as_str(&self.err_type) - } - - fn cause(&self) -> Option<&Error> { - self.cause.as_ref().map(|e| &**e) - } - -} +generate_error_types!(NoteError, NoteErrorKind, + StoreWriteError => "Error writing store", + StoreReadError => "Error reading store", + HeaderTypeError => "Header type error", + NoteToEntryConversion => "Error converting Note instance to Entry instance" +); diff --git a/libimagnotes/src/lib.rs b/libimagnotes/src/lib.rs index 64ef75a2..ee43c9a3 100644 --- a/libimagnotes/src/lib.rs +++ b/libimagnotes/src/lib.rs @@ -20,6 +20,7 @@ extern crate toml; extern crate libimagrt; #[macro_use] extern crate libimagstore; +#[macro_use] extern crate libimagerror; extern crate libimagentrytag; module_entry_path_mod!("notes", "0.1.0"); |