ParserError: Add cause
This commit is contained in:
parent
1aaea39b3d
commit
3a76c05317
1 changed files with 14 additions and 1 deletions
|
@ -10,6 +10,7 @@ pub struct ParserError {
|
|||
parsertext: String,
|
||||
index: i32,
|
||||
explanation: Option<String>,
|
||||
caused_by: Option<Box<Error>>,
|
||||
}
|
||||
|
||||
impl ParserError {
|
||||
|
@ -19,6 +20,7 @@ impl ParserError {
|
|||
parsertext: text,
|
||||
index: idx,
|
||||
explanation: Some(String::from(expl)),
|
||||
caused_by: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,9 +29,16 @@ impl ParserError {
|
|||
summary: String::from(sum),
|
||||
parsertext: text,
|
||||
index: idx,
|
||||
explanation: None
|
||||
explanation: None,
|
||||
caused_by: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_cause(mut self, e: Box<Error>) -> ParserError {
|
||||
self.caused_by = Some(e);
|
||||
self
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Error for ParserError {
|
||||
|
@ -38,6 +47,10 @@ impl Error for ParserError {
|
|||
&self.summary[..]
|
||||
}
|
||||
|
||||
fn cause(&self) -> Option<&Error> {
|
||||
self.caused_by.as_ref().map(|e| &**e)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Debug for ParserError {
|
||||
|
|
Loading…
Reference in a new issue