diff rust/src/types.rs @ 604:278f1002b5c7 rust

sensor regex, custom error type
author Matt Johnston <matt@ucc.asn.au>
date Thu, 16 Feb 2017 23:53:46 +0800
parents b45b8b4cf0f5
children 7bda01659426
line wrap: on
line diff
--- a/rust/src/types.rs	Thu Feb 16 23:19:12 2017 +0800
+++ b/rust/src/types.rs	Thu Feb 16 23:53:46 2017 +0800
@@ -1,5 +1,8 @@
 use std::collections::HashMap;
 use std::time::Duration;
+use std::error::Error;
+use std::fmt;
+
 use serde::{Deserialize,Serialize};
 
 #[derive(Deserialize, Serialize, Debug)]
@@ -65,3 +68,32 @@
     }
 }
 
+#[derive(Debug)]
+pub struct TemplogError {
+    desc: String,
+}
+
+impl Error for TemplogError {
+    fn description(&self) -> &str { &self.desc }
+    fn cause(&self) -> Option<&Error> { None }
+}
+
+impl fmt::Display for TemplogError {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "TemplogError: {}", self.desc);
+        Ok(())
+    }
+
+
+}
+
+impl TemplogError {
+    pub fn new(desc: &str) -> Self {
+        TemplogError { 
+            desc: desc.to_string(),
+        }
+    }
+}
+
+
+