From c9be7a7483a076a2ffc240adc9100a7e22a6a7f7 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 6 Jul 2016 20:11:31 +0200 Subject: [PATCH] Move read::* code to the place where it belongs --- libimagtodo/src/lib.rs | 1 - libimagtodo/src/read.rs | 49 ----------------------------------------- libimagtodo/src/task.rs | 47 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 51 deletions(-) delete mode 100644 libimagtodo/src/read.rs 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 { - 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>; -} - -impl<'a> FromStoreId for Task<'a> { - - fn from_storeid<'b>(store: &'b Store, id: StoreId) -> Result> { - 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>; - - fn next(&mut self) -> Option>> { - 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 { + 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>; +} + +impl<'a> FromStoreId for Task<'a> { + + fn from_storeid<'b>(store: &'b Store, id: StoreId) -> Result> { + 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>; + + fn next(&mut self) -> Option>> { + self.iditer.next().map(|id| Task::from_storeid(self.store, id)) + } +} +