summaryrefslogtreecommitdiffstats
path: root/libimagtodo
diff options
context:
space:
mode:
authorRoman Schemenau <roman.schemenau@hs-furtwangen.de>2016-06-01 13:01:19 +0200
committerRoman Schemenau <roman.schemenau@hs-furtwangen.de>2016-06-01 13:01:19 +0200
commit41dfd51f8b5d7c4fd49e0cc8330e14bf0d13f46a (patch)
treed4f6afbe47c84e43dc875153890b1949e6ccdb41 /libimagtodo
parent66e57bf57c2dbce6265ebbe4ba3ebb696acf582b (diff)
Implement Read
Diffstat (limited to 'libimagtodo')
-rw-r--r--libimagtodo/src/read.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/libimagtodo/src/read.rs b/libimagtodo/src/read.rs
index e69de29b..28e78d35 100644
--- a/libimagtodo/src/read.rs
+++ b/libimagtodo/src/read.rs
@@ -0,0 +1,67 @@
+
+
+use libimagstore::storeid::StoreIdIterator;
+use libimagstore::store::{FileLockEntry, Store};
+use libimagstore::storeid::StoreId;
+use module_path::ModuleEntryPath;
+use error::{TodoError, TodoErrorKind};
+
+use std::result::Result as RResult;
+
+pub type Result<T> = RResult<T, TodoError>;
+
+pub struct Read<'a> {
+ entry: FileLockEntry<'a>,
+}
+
+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 {
+ fn from_storeid<'a>(&'a Store, StoreId) -> Result<Read<'a>>;
+}
+
+impl<'a> FromStoreId for Read<'a> {
+
+ fn from_storeid<'b>(store: &'b Store, id: StoreId) -> Result<Read<'b>> {
+ match store.retrieve(id) {
+ Err(e) => Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))),
+ Ok(c) => Ok(Read { entry: c }),
+ }
+ }
+
+}
+
+
+pub struct ReadIterator<'a> {
+ store: &'a Store,
+ iditer: StoreIdIterator,
+}
+
+impl<'a> ReadIterator<'a> {
+
+ pub fn new(store: &'a Store, iditer: StoreIdIterator) -> ReadIterator<'a> {
+ ReadIterator {
+ store: store,
+ iditer: iditer,
+ }
+ }
+
+}
+
+impl<'a> Iterator for ReadIterator<'a> {
+ type Item = Result<Read<'a>>;
+
+ fn next(&mut self) -> Option<Result<Read<'a>>> {
+ self.iditer
+ .next()
+ .map(|id| Read::from_storeid(self.store, id))
+ }
+
+}