Renamed function and iterator
This commit is contained in:
parent
41dfd51f8b
commit
84581c73ca
1 changed files with 29 additions and 40 deletions
|
@ -1,67 +1,56 @@
|
||||||
|
|
||||||
|
use libimagstore::storeid::{StoreIdIterator, StoreId};
|
||||||
use libimagstore::storeid::StoreIdIterator;
|
use libimagstore::store::Store;
|
||||||
use libimagstore::store::{FileLockEntry, Store};
|
|
||||||
use libimagstore::storeid::StoreId;
|
|
||||||
use module_path::ModuleEntryPath;
|
|
||||||
use error::{TodoError, TodoErrorKind};
|
use error::{TodoError, TodoErrorKind};
|
||||||
|
use task::Task;
|
||||||
|
|
||||||
use std::result::Result as RResult;
|
use std::result::Result as RResult;
|
||||||
|
|
||||||
pub type Result<T> = RResult<T, TodoError>;
|
pub type Result<T> = RResult<T, TodoError>;
|
||||||
|
|
||||||
pub struct Read<'a> {
|
|
||||||
entry: FileLockEntry<'a>,
|
pub fn all_todos(store: &Store) -> Result<TaskIterator> {
|
||||||
|
|
||||||
|
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<ReadIterator> {
|
|
||||||
store.retrieve_for_module("uuid")
|
|
||||||
.map(|iter| ReadIterator::new(store, iter))
|
|
||||||
.map_err(|e| TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e))))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
trait FromStoreId {
|
trait FromStoreId {
|
||||||
fn from_storeid<'a>(&'a Store, StoreId) -> Result<Read<'a>>;
|
fn from_storeid<'a>(&'a Store, StoreId) -> Result<Task<'a>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> FromStoreId for Read<'a> {
|
impl<'a> FromStoreId for Task<'a> {
|
||||||
|
|
||||||
fn from_storeid<'b>(store: &'b Store, id: StoreId) -> Result<Read<'b>> {
|
fn from_storeid<'b>(store: &'b Store, id: StoreId) -> Result<Task<'b>> {
|
||||||
match store.retrieve(id) {
|
match store.retrieve(id) {
|
||||||
Err(e) => Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))),
|
Err(e) => Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))),
|
||||||
Ok(c) => Ok(Read { entry: c }),
|
Ok(c) => Ok(Task::new( c )),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct TaskIterator<'a> {
|
||||||
pub struct ReadIterator<'a> {
|
|
||||||
store: &'a Store,
|
store: &'a Store,
|
||||||
iditer: StoreIdIterator,
|
iditer: StoreIdIterator,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ReadIterator<'a> {
|
impl<'a> TaskIterator<'a> {
|
||||||
|
|
||||||
pub fn new(store: &'a Store, iditer: StoreIdIterator) -> ReadIterator<'a> {
|
pub fn new(store: &'a Store, iditer: StoreIdIterator) -> TaskIterator<'a> {
|
||||||
ReadIterator {
|
TaskIterator {
|
||||||
store: store,
|
store: store,
|
||||||
iditer: iditer,
|
iditer: iditer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Iterator for ReadIterator<'a> {
|
impl<'a> Iterator for TaskIterator<'a> {
|
||||||
type Item = Result<Read<'a>>;
|
type Item = Result<Task<'a>>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Result<Read<'a>>> {
|
fn next(&mut self) -> Option<Result<Task<'a>>> {
|
||||||
self.iditer
|
self.iditer
|
||||||
.next()
|
.next()
|
||||||
.map(|id| Read::from_storeid(self.store, id))
|
.map(|id| Task::from_storeid(self.store, id))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue