aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorTill Hoeppner2015-07-24 00:02:16 +0200
committerTill Hoeppner2015-07-24 00:02:16 +0200
commit4ce03bf5f95c9b5099c890ac9de68596c5a3b1ff (patch)
tree841fa9938c4f8c0ae249ac3532a0ff245cc1acdb /src/lib.rs
parent47ebf402a67df74af0a25a3cac92012170029ad4 (diff)
downloadilc-4ce03bf5f95c9b5099c890ac9de68596c5a3b1ff.tar.gz
ilc-4ce03bf5f95c9b5099c890ac9de68596c5a3b1ff.tar.xz
ilc-4ce03bf5f95c9b5099c890ac9de68596c5a3b1ff.zip
Half-decent error reporting
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 7e4de8b..55ebdf8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -27,6 +27,8 @@ pub mod context;
use std::convert::From;
use std::{ io, result };
+use std::error::Error;
+use std::fmt::{ self, Display, Formatter };
use chrono::format::ParseError;
@@ -41,6 +43,31 @@ pub enum IlcError {
Io(io::Error)
}
+impl Display for IlcError {
+ fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
+ fmt.write_str(self.description())
+ }
+}
+
+impl Error for IlcError {
+ fn description(&self) -> &str {
+ use IlcError::*;
+ match self {
+ &Parse(_) => "error while parsing",
+ &Chrono(_) => "error while parsing time strings",
+ &BincodeDecode => "error while decoding from binary",
+ &BincodeEncode => "error while encoding to binary",
+ &Io(_) => "error during input/output"
+ }
+ }
+
+ fn cause(&self) -> Option<&Error> {
+ match self {
+ _ => None
+ }
+ }
+}
+
impl From<ParseError> for IlcError {
fn from(err: ParseError) -> IlcError { IlcError::Chrono(err) }
}