summaryrefslogtreecommitdiffstats
path: root/libimagcounter
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-05-15 16:53:31 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-05-17 00:26:36 +0200
commit8602d5855a1b9b661516bc93db69850605b0253e (patch)
tree58d5c493c6f44d603d5730942fe5b976f8ec7422 /libimagcounter
parent9140c36301dc8c1c6792b8806058b40406d03982 (diff)
libimagcounter: Replace error code with code generator macro
Diffstat (limited to 'libimagcounter')
-rw-r--r--libimagcounter/Cargo.toml3
-rw-r--r--libimagcounter/src/error.rs87
-rw-r--r--libimagcounter/src/lib.rs1
3 files changed, 10 insertions, 81 deletions
diff --git a/libimagcounter/Cargo.toml b/libimagcounter/Cargo.toml
index 8d880182..da194678 100644
--- a/libimagcounter/Cargo.toml
+++ b/libimagcounter/Cargo.toml
@@ -11,3 +11,6 @@ semver = "0.2"
[dependencies.libimagstore]
path = "../libimagstore"
+[dependencies.libimagerror]
+path = "../libimagerror"
+
diff --git a/libimagcounter/src/error.rs b/libimagcounter/src/error.rs
index 1aa347a6..f2e11eeb 100644
--- a/libimagcounter/src/error.rs
+++ b/libimagcounter/src/error.rs
@@ -2,85 +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 CounterErrorKind {
- StoreReadError,
- StoreWriteError,
- HeaderTypeError,
- HeaderFieldMissingError,
-}
-
-fn counter_error_type_as_str(e: &CounterErrorKind) -> &'static str {
- match *e {
- CounterErrorKind::StoreReadError => "Store read error",
- CounterErrorKind::StoreWriteError => "Store write error",
- CounterErrorKind::HeaderTypeError => "Header type error",
- CounterErrorKind::HeaderFieldMissingError => "Header field missing error",
- }
-}
-
-impl Display for CounterErrorKind {
-
- fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
- try!(write!(fmt, "{}", counter_error_type_as_str(self)));
- Ok(())
- }
-
-}
-
-/**
- * Store error type
- */
-#[derive(Debug)]
-pub struct CounterError {
- err_type: CounterErrorKind,
- cause: Option<Box<Error>>,
-}
-
-impl CounterError {
-
- /**
- * Build a new CounterError from an CounterErrorKind, optionally with cause
- */
- pub fn new(errtype: CounterErrorKind, cause: Option<Box<Error>>)
- -> CounterError
- {
- CounterError {
- err_type: errtype,
- cause: cause,
- }
- }
-
- /**
- * Get the error type of this CounterError
- */
- pub fn err_type(&self) -> CounterErrorKind {
- self.err_type
- }
-
-}
-
-impl Display for CounterError {
-
- fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
- try!(write!(fmt, "[{}]", counter_error_type_as_str(&self.err_type)));
- Ok(())
- }
-
-}
-
-impl Error for CounterError {
-
- fn description(&self) -> &str {
- counter_error_type_as_str(&self.err_type)
- }
-
- fn cause(&self) -> Option<&Error> {
- self.cause.as_ref().map(|e| &**e)
- }
-
-}
+generate_error_types!(CounterError, CounterErrorKind,
+ StoreReadError => "Store read error",
+ StoreWriteError => "Store write error",
+ HeaderTypeError => "Header type error",
+ HeaderFieldMissingError => "Header field missing error"
+);
diff --git a/libimagcounter/src/lib.rs b/libimagcounter/src/lib.rs
index 77033170..0426384d 100644
--- a/libimagcounter/src/lib.rs
+++ b/libimagcounter/src/lib.rs
@@ -17,6 +17,7 @@ extern crate toml;
#[macro_use] extern crate semver;
#[macro_use] extern crate libimagstore;
+#[macro_use] extern crate libimagerror;
module_entry_path_mod!("counter", "0.1.0");