diff options
-rw-r--r-- | libimagtodo/src/lib.rs | 1 | ||||
-rw-r--r-- | libimagtodo/src/read.rs | 49 | ||||
-rw-r--r-- | libimagtodo/src/task.rs | 47 |
3 files changed, 46 insertions, 51 deletions
diff --git a/libimagtodo/src/lib.rs b/libimagtodo/src/lib.rs index cf1f966c..bc217a4b 100644 --- a/libimagtodo/src/lib.rs +++ b/libimagtodo/src/lib.rs @@ -8,7 +8,6 @@ extern crate task_hookrs; module_entry_path_mod!("todo", "0.1.0"); pub mod error; -pub mod read; pub mod result; pub mod task; diff --git a/libimagtodo/src/read.rs b/libimagtodo/src/read.rs deleted file mode 100644 index f547ac30..00000000 --- a/libimagtodo/src/read.rs +++ /dev/null @@ -1,49 +0,0 @@ -use libimagstore::storeid::{StoreIdIterator, StoreId}; -use libimagstore::store::Store; -use error::{TodoError, TodoErrorKind}; -use task::Task; -use result::Result; - -pub fn get_todo_iterator(store: &Store) -> Result<TaskIterator> { - store.retrieve_for_module("todo/taskwarrior") - .map(|iter| TaskIterator::new(store, iter)) - .map_err(|e| TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))) -} - -trait FromStoreId { - fn from_storeid<'a>(&'a Store, StoreId) -> Result<Task<'a>>; -} - -impl<'a> FromStoreId for Task<'a> { - - fn from_storeid<'b>(store: &'b Store, id: StoreId) -> Result<Task<'b>> { - match store.retrieve(id) { - Err(e) => Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))), - Ok(c) => Ok(Task::new( c )), - } - } -} - -pub struct TaskIterator<'a> { - store: &'a Store, - iditer: StoreIdIterator, -} - -impl<'a> TaskIterator<'a> { - - pub fn new(store: &'a Store, iditer: StoreIdIterator) -> TaskIterator<'a> { - TaskIterator { - store: store, - iditer: iditer, - } - } - -} - -impl<'a> Iterator for TaskIterator<'a> { - type Item = Result<Task<'a>>; - - fn next(&mut self) -> Option<Result<Task<'a>>> { - self.iditer.next().map(|id| Task::from_storeid(self.store, id)) - } -} diff --git a/libimagtodo/src/task.rs b/libimagtodo/src/task.rs index ebfb4b7e..3bf897d8 100644 --- a/libimagtodo/src/task.rs +++ b/libimagtodo/src/task.rs @@ -7,7 +7,7 @@ use uuid::Uuid; use task_hookrs::task::Task as TTask; use libimagstore::store::{FileLockEntry, Store}; -use libimagstore::storeid::IntoStoreId; +use libimagstore::storeid::{IntoStoreId, StoreIdIterator, StoreId}; use module_path::ModuleEntryPath; use error::{TodoError, TodoErrorKind}; @@ -29,6 +29,12 @@ impl<'a> Task<'a> { .map_err(|e| TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))) } + pub fn all(store: &Store) -> Result<TaskIterator> { + store.retrieve_for_module("todo/taskwarrior") + .map(|iter| TaskIterator::new(store, iter)) + .map_err(|e| TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))) + } + } impl<'a> Deref for Task<'a> { @@ -106,3 +112,42 @@ impl<'a> IntoTask<'a> for TTask { } } + +trait FromStoreId { + fn from_storeid<'a>(&'a Store, StoreId) -> Result<Task<'a>>; +} + +impl<'a> FromStoreId for Task<'a> { + + fn from_storeid<'b>(store: &'b Store, id: StoreId) -> Result<Task<'b>> { + match store.retrieve(id) { + Err(e) => Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))), + Ok(c) => Ok(Task::new( c )), + } + } +} + +pub struct TaskIterator<'a> { + store: &'a Store, + iditer: StoreIdIterator, +} + +impl<'a> TaskIterator<'a> { + + pub fn new(store: &'a Store, iditer: StoreIdIterator) -> TaskIterator<'a> { + TaskIterator { + store: store, + iditer: iditer, + } + } + +} + +impl<'a> Iterator for TaskIterator<'a> { + type Item = Result<Task<'a>>; + + fn next(&mut self) -> Option<Result<Task<'a>>> { + self.iditer.next().map(|id| Task::from_storeid(self.store, id)) + } +} + |