summaryrefslogtreecommitdiffstats
path: root/libimagtodo
diff options
context:
space:
mode:
authormario <mario-krehl@gmx.de>2016-05-09 12:11:13 +0200
committermario <mario-krehl@gmx.de>2016-05-09 12:11:13 +0200
commit26ec9710ccd27fd5f29c2ff8917b881ea32ed655 (patch)
tree4ee6fcf460090c9b29558ccd9b5a1ecd7e390141 /libimagtodo
parentdf6f41942be3e525c1578bad1a90fc8fbf17a802 (diff)
introduce ConversionError in error.rs and add trait for task_hookrs::task::Task to convert it to a libimagtodo::task::Task
Diffstat (limited to 'libimagtodo')
-rw-r--r--libimagtodo/src/error.rs60
-rw-r--r--libimagtodo/src/lib.rs1
-rw-r--r--libimagtodo/src/task.rs17
3 files changed, 75 insertions, 3 deletions
diff --git a/libimagtodo/src/error.rs b/libimagtodo/src/error.rs
new file mode 100644
index 00000000..4dafc389
--- /dev/null
+++ b/libimagtodo/src/error.rs
@@ -0,0 +1,60 @@
+use std::error::Error;
+use std::clone::Clone;
+use std::fmt::Error as FmtError;
+use std::fmt::{Debug, Display, Formatter};
+use std::fmt;
+
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub enum TodoErrorKind {
+ ConversionError,
+}
+
+fn todo_error_type_as_str(e: &TodoErrorKind) -> &'static str {
+ match e {
+ &TodoErrorKind::ConversionError => "Conversion Error",
+ }
+}
+
+impl Display for TodoErrorKind {
+ fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
+ try!(write!(fmt, "{}", todo_error_type_as_str(self)));
+ Ok(())
+ }
+}
+
+#[derive(Debug)]
+pub struct TodoError {
+ err_type : TodoErrorKind,
+ cause : Option<Box<Error>>,
+}
+
+impl TodoError {
+ pub fn new(errtype : TodoErrorKind, cause : Option<Box<Error>>) -> TodoError {
+ TodoError {
+ err_type : errtype,
+ cause : cause,
+ }
+ }
+ pub fn err_type(&self) -> TodoErrorKind {
+ self.err_type.clone()
+ }
+}
+
+impl Display for TodoError {
+ fn fmt(&self, fmt : &mut Formatter) -> Result<(), FmtError> {
+ try!(write!(fmt, "[{}]", todo_error_type_as_str(&self.err_type.clone())));
+ Ok(())
+ }
+}
+
+impl Error for TodoError {
+ fn description(&self) -> &str {
+ todo_error_type_as_str(&self.err_type.clone())
+ }
+ fn cause(&self) -> Option<&Error> {
+ self.cause.as_ref().map(|e| &**e)
+ }
+}
+
+
+
diff --git a/libimagtodo/src/lib.rs b/libimagtodo/src/lib.rs
index 9913f7b4..f1eaf3a3 100644
--- a/libimagtodo/src/lib.rs
+++ b/libimagtodo/src/lib.rs
@@ -6,6 +6,7 @@ extern crate task_hookrs;
module_entry_path_mod!("todo", "0.1.0");
+pub mod error;
pub mod task;
pub mod delete;
pub mod read;
diff --git a/libimagtodo/src/task.rs b/libimagtodo/src/task.rs
index 41f71cee..66517528 100644
--- a/libimagtodo/src/task.rs
+++ b/libimagtodo/src/task.rs
@@ -5,12 +5,18 @@ use task_hookrs::task::Task as TTask;
use libimagstore::store::FileLockEntry;
+use error::{TodoError, TodoErrorKind};
+
+pub trait IntoTask<'a> {
+ fn into_filelockentry(self) -> Result<Task<'a>, TodoError>;
+}
+
#[derive(Debug)]
pub struct Task<'a> {
flentry : FileLockEntry<'a>,
- uuid : Uuid,
+ //uuid : Uuid,
}
-
+/*
impl<'a> From<TTask> for Task<'a> {
fn from(ttask : TTask) -> Task<'a> {
Task {
@@ -19,4 +25,9 @@ impl<'a> From<TTask> for Task<'a> {
}
}
}
-
+*/
+impl<'a> IntoTask<'a> for TTask {
+ fn into_filelockentry(self) -> Result<Task<'a>, TodoError> {
+ Err(TodoError::new(TodoErrorKind::ConversionError, None))
+ }
+}