From 3a76c05317bbdee77ac516e53206f3869db447d8 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 4 Dec 2015 13:12:17 +0100 Subject: [PATCH] ParserError: Add cause --- src/storage/parser.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/storage/parser.rs b/src/storage/parser.rs index bc0ed5b0..6e010a85 100644 --- a/src/storage/parser.rs +++ b/src/storage/parser.rs @@ -10,6 +10,7 @@ pub struct ParserError { parsertext: String, index: i32, explanation: Option, + caused_by: Option>, } 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) -> 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 {