diff --git a/libimagtodo/src/read.rs b/libimagtodo/src/read.rs index 28e78d35..9129fb60 100644 --- a/libimagtodo/src/read.rs +++ b/libimagtodo/src/read.rs @@ -1,67 +1,56 @@ - -use libimagstore::storeid::StoreIdIterator; -use libimagstore::store::{FileLockEntry, Store}; -use libimagstore::storeid::StoreId; -use module_path::ModuleEntryPath; +use libimagstore::storeid::{StoreIdIterator, StoreId}; +use libimagstore::store::Store; use error::{TodoError, TodoErrorKind}; +use task::Task; use std::result::Result as RResult; pub type Result = RResult; -pub struct Read<'a> { - entry: FileLockEntry<'a>, + +pub fn all_todos(store: &Store) -> Result { + + store.retrieve_for_module("uuid") + .map(|iter| TaskIterator::new(store, iter)) + .map_err(|e| TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))) } -pub fn all_uuids(store: &Store) -> Result { - store.retrieve_for_module("uuid") - .map(|iter| ReadIterator::new(store, iter)) - .map_err(|e| TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))) -} - - - - trait FromStoreId { - fn from_storeid<'a>(&'a Store, StoreId) -> Result>; + fn from_storeid<'a>(&'a Store, StoreId) -> Result>; } -impl<'a> FromStoreId for Read<'a> { +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(Read { entry: c }), - } + 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 ReadIterator<'a> { +pub struct TaskIterator<'a> { store: &'a Store, iditer: StoreIdIterator, } -impl<'a> ReadIterator<'a> { +impl<'a> TaskIterator<'a> { - pub fn new(store: &'a Store, iditer: StoreIdIterator) -> ReadIterator<'a> { - ReadIterator { - store: store, - iditer: iditer, - } + pub fn new(store: &'a Store, iditer: StoreIdIterator) -> TaskIterator<'a> { + TaskIterator { + store: store, + iditer: iditer, + } } - } -impl<'a> Iterator for ReadIterator<'a> { - type Item = Result>; +impl<'a> Iterator for TaskIterator<'a> { + type Item = Result>; - fn next(&mut self) -> Option>> { - self.iditer - .next() - .map(|id| Read::from_storeid(self.store, id)) + fn next(&mut self) -> Option>> { + self.iditer + .next() + .map(|id| Task::from_storeid(self.store, id)) } - }