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,
|
parsertext: String,
|
||||||
index: i32,
|
index: i32,
|
||||||
explanation: Option<String>,
|
explanation: Option<String>,
|
||||||
|
caused_by: Option<Box<Error>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParserError {
|
impl ParserError {
|
||||||
|
@ -19,6 +20,7 @@ impl ParserError {
|
||||||
parsertext: text,
|
parsertext: text,
|
||||||
index: idx,
|
index: idx,
|
||||||
explanation: Some(String::from(expl)),
|
explanation: Some(String::from(expl)),
|
||||||
|
caused_by: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,9 +29,16 @@ impl ParserError {
|
||||||
summary: String::from(sum),
|
summary: String::from(sum),
|
||||||
parsertext: text,
|
parsertext: text,
|
||||||
index: idx,
|
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 {
|
impl Error for ParserError {
|
||||||
|
@ -38,6 +47,10 @@ impl Error for ParserError {
|
||||||
&self.summary[..]
|
&self.summary[..]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cause(&self) -> Option<&Error> {
|
||||||
|
self.caused_by.as_ref().map(|e| &**e)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for ParserError {
|
impl Debug for ParserError {
|
||||||
|
|
Loading…
Reference in a new issue