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 | 5c7412ebc6cf48b9814085b83987d6d2086c8c13 (patch) | |
tree | 679e7db6a7f9cf37fd135d8cc636f5927ac2df8b /libimagentrytag | |
parent | 20ac5247f1be9cb65fd511e4a3ce693a45dd8a8a (diff) |
libimagentrytag: Replace error code with code generator macro
Diffstat (limited to 'libimagentrytag')
-rw-r--r-- | libimagentrytag/Cargo.toml | 3 | ||||
-rw-r--r-- | libimagentrytag/src/error.rs | 69 | ||||
-rw-r--r-- | libimagentrytag/src/lib.rs | 1 |
3 files changed, 10 insertions, 63 deletions
diff --git a/libimagentrytag/Cargo.toml b/libimagentrytag/Cargo.toml index db2df486..2a4e1ed2 100644 --- a/libimagentrytag/Cargo.toml +++ b/libimagentrytag/Cargo.toml @@ -13,3 +13,6 @@ itertools = "0.4" [dependencies.libimagstore] path = "../libimagstore" +[dependencies.libimagerror] +path = "../libimagerror" + diff --git a/libimagentrytag/src/error.rs b/libimagentrytag/src/error.rs index 19d4a92e..5be68b90 100644 --- a/libimagentrytag/src/error.rs +++ b/libimagentrytag/src/error.rs @@ -2,67 +2,10 @@ use std::error::Error; use std::fmt::Error as FmtError; use std::fmt::{Display, Formatter}; -#[derive(Clone, Copy, Debug, PartialEq)] -pub enum TagErrorKind { - TagTypeError, - HeaderReadError, - HeaderWriteError, - NotATag, -} - -fn tag_error_type_as_str(e: &TagErrorKind) -> &'static str { - match *e { - TagErrorKind::TagTypeError => "Entry Header Tag Type wrong", - TagErrorKind::HeaderReadError => "Error while reading entry header", - TagErrorKind::HeaderWriteError => "Error while writing entry header", - TagErrorKind::NotATag => "String is not a tag", - } -} - -impl Display for TagErrorKind { - - fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { - try!(write!(fmt, "{}", tag_error_type_as_str(self))); - Ok(()) - } - -} - -#[derive(Debug)] -pub struct TagError { - kind: TagErrorKind, - cause: Option<Box<Error>>, -} - -impl TagError { - - pub fn new(errtype: TagErrorKind, cause: Option<Box<Error>>) -> TagError { - TagError { - kind: errtype, - cause: cause, - } - } - -} - -impl Display for TagError { - - fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { - try!(write!(fmt, "[{}]", tag_error_type_as_str(&self.kind))); - Ok(()) - } - -} - -impl Error for TagError { - - fn description(&self) -> &str { - tag_error_type_as_str(&self.kind) - } - - fn cause(&self) -> Option<&Error> { - self.cause.as_ref().map(|e| &**e) - } - -} +generate_error_types!(TagError, TagErrorKind, + TagTypeError => "Entry Header Tag Type wrong", + HeaderReadError => "Error while reading entry header", + HeaderWriteError => "Error while writing entry header", + NotATag => "String is not a tag" +); diff --git a/libimagentrytag/src/lib.rs b/libimagentrytag/src/lib.rs index d90f5fa5..232de3b3 100644 --- a/libimagentrytag/src/lib.rs +++ b/libimagentrytag/src/lib.rs @@ -19,6 +19,7 @@ extern crate regex; extern crate toml; extern crate libimagstore; +#[macro_use] extern crate libimagerror; pub mod error; pub mod exec; |