diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-05-15 16:41:25 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-05-17 00:26:35 +0200 |
commit | 42f7e086a32d805f2965058b08cbdf303a331cb5 (patch) | |
tree | a2ed7c875c2f95a7113285c2ab81907a7a6deb24 /libimagstore | |
parent | 627fa7de46701a1848ffe8c464cc7dc4a1618b0c (diff) |
Replace error code with macro for code generation
Diffstat (limited to 'libimagstore')
-rw-r--r-- | libimagstore/src/hook/error.rs | 82 |
1 files changed, 4 insertions, 78 deletions
diff --git a/libimagstore/src/hook/error.rs b/libimagstore/src/hook/error.rs index b9abd4fe..ec06dd98 100644 --- a/libimagstore/src/hook/error.rs +++ b/libimagstore/src/hook/error.rs @@ -3,14 +3,10 @@ use std::fmt::Error as FmtError; use std::fmt::{Display, Formatter}; use std::convert::Into; -/** - * Kind of error - */ -#[derive(Clone, Copy, Debug)] -pub enum HookErrorKind { - HookExecutionError, - AccessTypeViolation, -} +generate_error_types!(HookError, HookErrorKind, + HookExecutionError => "Hook exec error", + AccessTypeViolation => "Hook access type violation" +); pub trait IntoHookError { fn into_hookerror(self) -> HookError; @@ -33,73 +29,3 @@ impl Into<HookError> for (HookErrorKind, Box<Error>) { } -fn hook_error_type_as_str(e: &HookErrorKind) -> &'static str { - match *e { - HookErrorKind::HookExecutionError => "Hook exec error", - HookErrorKind::AccessTypeViolation => "Hook access type violation", - } -} - -impl Display for HookErrorKind { - - fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { - try!(write!(fmt, "{}", hook_error_type_as_str(self))); - Ok(()) - } - -} - -/** - * Error type - */ -#[derive(Debug)] -pub struct HookError { - err_type: HookErrorKind, - cause: Option<Box<Error>>, -} - -impl HookError { - - /** - * Build a new HookError from an HookErrorKind, optionally with cause - */ - pub fn new(errtype: HookErrorKind, cause: Option<Box<Error>>) - -> HookError - { - HookError { - err_type: errtype, - cause: cause, - } - } - - /** - * Get the error type of this HookError - */ - pub fn err_type(&self) -> HookErrorKind { - self.err_type - } - -} - -impl Display for HookError { - - fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { - try!(write!(fmt, "[{}]", hook_error_type_as_str(&self.err_type))); - Ok(()) - } - -} - -impl Error for HookError { - - fn description(&self) -> &str { - hook_error_type_as_str(&self.err_type) - } - - fn cause(&self) -> Option<&Error> { - self.cause.as_ref().map(|e| &**e) - } - -} - - |