Move read::* code to the place where it belongs
This commit is contained in:
parent
df5abef447
commit
c9be7a7483
3 changed files with 46 additions and 51 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue