diff --git a/libimaginteraction/Cargo.toml b/libimaginteraction/Cargo.toml index e0bea398..1ee8e63f 100644 --- a/libimaginteraction/Cargo.toml +++ b/libimaginteraction/Cargo.toml @@ -20,3 +20,6 @@ path = "../libimagentryfilter" [dependencies.libimagutil] path = "../libimagutil" +[dependencies.libimagerror] +path = "../libimagerror" + diff --git a/libimaginteraction/src/error.rs b/libimaginteraction/src/error.rs index ed7d974e..a85c9b25 100644 --- a/libimaginteraction/src/error.rs +++ b/libimaginteraction/src/error.rs @@ -2,76 +2,7 @@ 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 InteractionErrorKind { - Unknown -} - -fn interaction_error_type_as_str(e: &InteractionErrorKind) -> &'static str { - match *e { - InteractionErrorKind::Unknown => "Unknown Error", - } -} - -impl Display for InteractionErrorKind { - - fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { - try!(write!(fmt, "{}", interaction_error_type_as_str(self))); - Ok(()) - } - -} - -#[derive(Debug)] -pub struct InteractionError { - err_type: InteractionErrorKind, - cause: Option>, -} - -impl InteractionError { - - /** - * Build a new InteractionError from an InteractionErrorKind, optionally with cause - */ - pub fn new(errtype: InteractionErrorKind, cause: Option>) - -> InteractionError - { - InteractionError { - err_type: errtype, - cause: cause, - } - } - - /** - * Get the error type of this InteractionError - */ - pub fn err_type(&self) -> InteractionErrorKind { - self.err_type - } - -} - -impl Display for InteractionError { - - fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { - try!(write!(fmt, "[{}]", interaction_error_type_as_str(&self.err_type))); - Ok(()) - } - -} - -impl Error for InteractionError { - - fn description(&self) -> &str { - interaction_error_type_as_str(&self.err_type) - } - - fn cause(&self) -> Option<&Error> { - self.cause.as_ref().map(|e| &**e) - } - -} +generate_error_types!(InteractionError, InteractionErrorKind, + Unknown => "Unknown Error" +); diff --git a/libimaginteraction/src/lib.rs b/libimaginteraction/src/lib.rs index ff0fff06..3600b942 100644 --- a/libimaginteraction/src/lib.rs +++ b/libimaginteraction/src/lib.rs @@ -8,6 +8,7 @@ extern crate regex; extern crate libimagentryfilter; extern crate libimagstore; #[macro_use] extern crate libimagutil; +#[macro_use] extern crate libimagerror; pub mod ask; pub mod error;