Pass error members on ::new()

This commit is contained in:
Matthias Beyer 2016-01-16 13:39:53 +01:00
parent 48c3cc5f5d
commit 180eab2652

View file

@ -58,17 +58,19 @@ impl Display for StoreErrorType {
pub struct StoreError { pub struct StoreError {
err_type: StoreErrorType, err_type: StoreErrorType,
expl: Option<&'static str>, expl: &'static str,
cause: Option<Box<Error>>, cause: Option<Box<Error>>,
} }
impl StoreError { impl StoreError {
pub fn new() -> StoreError { pub fn new(errtype: StoreErrorType, expl: &'static str, cause: Option<Box<Error>>)
-> StoreError
{
StoreError { StoreError {
err_type: StoreErrorType::Unknown, err_type: errtype,
expl: None, expl: expl,
cause: None, cause: cause,
} }
} }
@ -76,21 +78,6 @@ impl StoreError {
self.err_type.clone() 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<Error>) -> StoreError {
self.cause = Some(e);
self
}
} }
impl Debug for StoreError { impl Debug for StoreError {
@ -107,9 +94,7 @@ impl Display for StoreError {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
let e : String = self.err_type.clone().into(); let e : String = self.err_type.clone().into();
try!(write!(fmt, "[{}]: {}", try!(write!(fmt, "[{}]: {}", e, self.expl));
e,
self.expl.unwrap_or("")));
Ok(()) Ok(())
} }
@ -118,7 +103,7 @@ impl Display for StoreError {
impl Error for StoreError { impl Error for StoreError {
fn description(&self) -> &str { fn description(&self) -> &str {
self.expl.unwrap_or("") self.expl
} }
fn cause(&self) -> Option<&Error> { fn cause(&self) -> Option<&Error> {