summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-04-30 17:28:54 +0200
committerMatthias Beyer <mail@beyermatthias.de>2018-05-01 17:44:00 +0200
commite643f36fa3957022a2750848ac9b95051a29169e (patch)
tree0e6be1b45d2f5921c81731d9ddfed2834be0f045 /lib
parentbf0bef058d11380d8ba8bc4ecdf086bf6e2e2c23 (diff)
Refactor libimaghabit to fit new store iterator interface
Diffstat (limited to 'lib')
-rw-r--r--lib/domain/libimaghabit/src/habit.rs3
-rw-r--r--lib/domain/libimaghabit/src/iter.rs20
2 files changed, 16 insertions, 7 deletions
diff --git a/lib/domain/libimaghabit/src/habit.rs b/lib/domain/libimaghabit/src/habit.rs
index 36c9dcc0..cd53c290 100644
--- a/lib/domain/libimaghabit/src/habit.rs
+++ b/lib/domain/libimaghabit/src/habit.rs
@@ -131,7 +131,8 @@ impl HabitTemplate for Entry {
let iter = self
.get_internal_links()?
.map(|link| link.get_store_id().clone())
- .filter(IsHabitCheck::is_habit_instance);
+ .filter(IsHabitCheck::is_habit_instance)
+ .map(Ok);
let sidi = StoreIdIterator::new(Box::new(iter));
Ok(HabitInstanceStoreIdIterator::new(sidi))
diff --git a/lib/domain/libimaghabit/src/iter.rs b/lib/domain/libimaghabit/src/iter.rs
index fa64f1ae..6a1af765 100644
--- a/lib/domain/libimaghabit/src/iter.rs
+++ b/lib/domain/libimaghabit/src/iter.rs
@@ -22,16 +22,21 @@ use libimagstore::storeid::StoreIdIteratorWithStore;
use libimagstore::storeid::StoreId;
use util::IsHabitCheck;
+use error::Result;
+use error::HabitError as HE;
pub struct HabitTemplateStoreIdIterator(StoreIdIterator);
impl Iterator for HabitTemplateStoreIdIterator {
- type Item = StoreId;
+ type Item = Result<StoreId>;
fn next(&mut self) -> Option<Self::Item> {
while let Some(n) = self.0.next() {
- if n.is_habit_template() {
- return Some(n)
+ match n {
+ Ok(n) => if n.is_habit_template() {
+ return Some(Ok(n))
+ },
+ Err(e) => return Some(Err(e).map_err(HE::from)),
}
}
None
@@ -59,12 +64,15 @@ impl HabitInstanceStoreIdIterator {
}
impl Iterator for HabitInstanceStoreIdIterator {
- type Item = StoreId;
+ type Item = Result<StoreId>;
fn next(&mut self) -> Option<Self::Item> {
while let Some(n) = self.0.next() {
- if n.is_habit_instance() {
- return Some(n)
+ match n {
+ Ok(n) => if n.is_habit_instance() {
+ return Some(Ok(n));
+ },
+ Err(e) => return Some(Err(e).map_err(HE::from)),
}
}
None