diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-05-15 16:53:31 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-05-17 14:01:58 +0200 |
commit | f27b114f850b94b1826faf9e07303ad9c7b96b9b (patch) | |
tree | 0c0c85a8fe82e1a6a7d26414206089e3aee80119 | |
parent | c730cce83baeb49cb90346456ccc2a09db675d75 (diff) |
libimagrt: Replace error code with code generator macro
-rw-r--r-- | libimagrt/Cargo.toml | 3 | ||||
-rw-r--r-- | libimagrt/src/error.rs | 59 | ||||
-rw-r--r-- | libimagrt/src/lib.rs | 1 |
3 files changed, 9 insertions, 54 deletions
diff --git a/libimagrt/Cargo.toml b/libimagrt/Cargo.toml index 485994b5..89610457 100644 --- a/libimagrt/Cargo.toml +++ b/libimagrt/Cargo.toml @@ -21,3 +21,6 @@ path = "../libimagstorestdhook" [dependencies.libimagutil] path = "../libimagutil" +[dependencies.libimagerror] +path = "../libimagerror" + diff --git a/libimagrt/src/error.rs b/libimagrt/src/error.rs index ca343ede..93752552 100644 --- a/libimagrt/src/error.rs +++ b/libimagrt/src/error.rs @@ -4,60 +4,11 @@ use std::fmt::Formatter; use std::fmt::Error as FmtError; use std::io::Error as IOError; -#[derive(Debug, PartialEq, Clone, Copy)] -pub enum RuntimeErrorKind { - Instantiate, - IOError, - ProcessExitFailure, - - // more? -} - -#[derive(Debug)] -pub struct RuntimeError { - kind: RuntimeErrorKind, - cause: Option<Box<Error>>, -} - -impl RuntimeError { - - pub fn new(kind: RuntimeErrorKind, cause: Option<Box<Error>>) -> RuntimeError { - RuntimeError { - kind: kind, - cause: cause, - } - } - -} - -fn runtime_error_kind_as_str(e: &RuntimeErrorKind) -> &'static str { - match *e { - RuntimeErrorKind::Instantiate => "Could not instantiate", - RuntimeErrorKind::IOError => "IO Error", - RuntimeErrorKind::ProcessExitFailure => "Process exited with failure", - } -} - -impl Display for RuntimeError { - - fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { - try!(write!(fmt, "{}", runtime_error_kind_as_str(&self.kind))); - Ok(()) - } - -} - -impl Error for RuntimeError { - - fn description(&self) -> &str { - runtime_error_kind_as_str(&self.kind) - } - - fn cause(&self) -> Option<&Error> { - self.cause.as_ref().map(|e| &**e) - } - -} +generate_error_types!(RuntimeError, RuntimeErrorKind, + Instantiate => "Could not instantiate", + IOError => "IO Error", + ProcessExitFailure => "Process exited with failure" +); impl From<IOError> for RuntimeError { diff --git a/libimagrt/src/lib.rs b/libimagrt/src/lib.rs index 7c9e3f59..ef0874e2 100644 --- a/libimagrt/src/lib.rs +++ b/libimagrt/src/lib.rs @@ -26,6 +26,7 @@ extern crate toml; extern crate libimagstore; extern crate libimagstorestdhook; extern crate libimagutil; +#[macro_use] extern crate libimagerror; mod configuration; mod logger; |