From 180eab2652a052824768245a86de958deb91668f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 16 Jan 2016 13:39:53 +0100 Subject: [PATCH] Pass error members on ::new() --- libimagstore/src/error.rs | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/libimagstore/src/error.rs b/libimagstore/src/error.rs index 5950769b..883fc7e2 100644 --- a/libimagstore/src/error.rs +++ b/libimagstore/src/error.rs @@ -58,17 +58,19 @@ impl Display for StoreErrorType { pub struct StoreError { err_type: StoreErrorType, - expl: Option<&'static str>, + expl: &'static str, cause: Option>, } impl StoreError { - pub fn new() -> StoreError { + pub fn new(errtype: StoreErrorType, expl: &'static str, cause: Option>) + -> StoreError + { StoreError { - err_type: StoreErrorType::Unknown, - expl: None, - cause: None, + err_type: errtype, + expl: expl, + cause: cause, } } @@ -76,21 +78,6 @@ impl StoreError { self.err_type.clone() } - pub fn with_type(mut self, t: StoreErrorType) -> StoreError { - self.err_type = t; - self - } - - pub fn with_expl(mut self, e: &'static str) -> StoreError { - self.expl = Some(e); - self - } - - pub fn with_cause(mut self, e: Box) -> StoreError { - self.cause = Some(e); - self - } - } impl Debug for StoreError { @@ -107,9 +94,7 @@ impl Display for StoreError { fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { let e : String = self.err_type.clone().into(); - try!(write!(fmt, "[{}]: {}", - e, - self.expl.unwrap_or(""))); + try!(write!(fmt, "[{}]: {}", e, self.expl)); Ok(()) } @@ -118,7 +103,7 @@ impl Display for StoreError { impl Error for StoreError { fn description(&self) -> &str { - self.expl.unwrap_or("") + self.expl } fn cause(&self) -> Option<&Error> {