diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-05-27 10:21:56 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-05-27 10:21:56 +0200 |
commit | 70b6a4f5878b2bfe19dd8a28541a0fbd8e73c281 (patch) | |
tree | 1bd614d4d9f426334123de5461f13bfe0dd0845c /libimagrt | |
parent | 2e80c29f47658a95023805a9a149058570bea16a (diff) |
Replace configuration error code with macro generator
Diffstat (limited to 'libimagrt')
-rw-r--r-- | libimagrt/src/configuration.rs | 73 |
1 files changed, 5 insertions, 68 deletions
diff --git a/libimagrt/src/configuration.rs b/libimagrt/src/configuration.rs index 15b94e09..3fb1c231 100644 --- a/libimagrt/src/configuration.rs +++ b/libimagrt/src/configuration.rs @@ -4,77 +4,14 @@ use std::ops::Deref; use toml::{Parser, Value}; -/** - * Errors which are related to configuration-file loading - */ -pub mod error { - use std::error::Error; - use std::fmt::{Display, Formatter}; - use std::fmt::Error as FmtError; - - /// The kind of an error - #[derive(Clone, Debug, PartialEq)] - pub enum ConfigErrorKind { - NoConfigFileFound, - } - - /// Configuration error type - #[derive(Debug)] - pub struct ConfigError { - kind: ConfigErrorKind, - cause: Option<Box<Error>>, - } - - impl ConfigError { - - /// Instantiate a new `ConfigError`, optionally with cause - pub fn new(kind: ConfigErrorKind, cause: Option<Box<Error>>) -> ConfigError { - ConfigError { - kind: kind, - cause: cause, - } - } - - ///get the Kind of the Error - pub fn err_type(&self) -> ConfigErrorKind { - self.kind.clone() - } - - /// Get the string, the `ConfigError` can be described with - pub fn as_str(e: &ConfigError) -> &'static str { - match e.err_type() { - ConfigErrorKind::NoConfigFileFound => "No config file found", - } - } - - } - - impl Display for ConfigError { - - fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { - try!(write!(fmt, "{}", ConfigError::as_str(self))); - Ok(()) - } - - } - - impl Error for ConfigError { - - fn description(&self) -> &str { - ConfigError::as_str(self) - } - - fn cause(&self) -> Option<&Error> { - self.cause.as_ref().map(|e| &**e) - } - - } - -} +generate_error_module!( + generate_error_types!(ConfigError, ConfigErrorKind, + NoConfigFileFound => "No config file found" + ); +); use self::error::{ConfigError, ConfigErrorKind}; - /** * Result type of this module. Either `T` or `ConfigError` */ |