summaryrefslogtreecommitdiffstats
path: root/libimagtag
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-02-04 14:05:30 +0100
committerMatthias Beyer <mail@beyermatthias.de>2016-02-14 19:34:01 +0100
commit15b1adbc206973b1ae4e8236cc8c1f90ef370ef8 (patch)
treec3fa66945b9d86605490008e8ea70a580a337342 /libimagtag
parentfd204ee05e6de5806ab4ae01819d8bcd52f981fa (diff)
Add error type implementation
Diffstat (limited to 'libimagtag')
-rw-r--r--libimagtag/src/error.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/libimagtag/src/error.rs b/libimagtag/src/error.rs
index e69de29b..321ecf1a 100644
--- a/libimagtag/src/error.rs
+++ b/libimagtag/src/error.rs
@@ -0,0 +1,63 @@
+use std::error::Error;
+use std::fmt::Error as FmtError;
+use std::clone::Clone;
+use std::fmt::{Debug, Display, Formatter};
+use std::fmt;
+
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub enum TagErrorKind {
+}
+
+fn tag_error_type_as_str(e: &TagErrorKind) -> &'static str {
+ match e {
+ _ => "",
+ }
+}
+
+impl Display for TagErrorKind {
+
+ fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
+ try!(write!(fmt, "{}", tag_error_type_as_str(self)));
+ Ok(())
+ }
+
+}
+
+#[derive(Debug)]
+pub struct TagError {
+ kind: TagErrorKind,
+ cause: Option<Box<Error>>,
+}
+
+impl TagError {
+
+ pub fn new(errtype: TagErrorKind, cause: Option<Box<Error>>) -> TagError {
+ TagError {
+ kind: errtype,
+ cause: cause,
+ }
+ }
+
+}
+
+impl Display for TagError {
+
+ fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
+ try!(write!(fmt, "[{}]", tag_error_type_as_str(&self.kind.clone())));
+ Ok(())
+ }
+
+}
+
+impl Error for TagError {
+
+ fn description(&self) -> &str {
+ tag_error_type_as_str(&self.kind.clone())
+ }
+
+ fn cause(&self) -> Option<&Error> {
+ self.cause.as_ref().map(|e| &**e)
+ }
+
+}
+