Pass error members on ::new()
This commit is contained in:
parent
48c3cc5f5d
commit
180eab2652
1 changed files with 9 additions and 24 deletions
|
@ -58,17 +58,19 @@ impl Display for StoreErrorType {
|
|||
|
||||
pub struct StoreError {
|
||||
err_type: StoreErrorType,
|
||||
expl: Option<&'static str>,
|
||||
expl: &'static str,
|
||||
cause: Option<Box<Error>>,
|
||||
}
|
||||
|
||||
impl StoreError {
|
||||
|
||||
pub fn new() -> StoreError {
|
||||
pub fn new(errtype: StoreErrorType, expl: &'static str, cause: Option<Box<Error>>)
|
||||
-> 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<Error>) -> 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> {
|
||||
|
|
Loading…
Reference in a new issue