Refactor libimaghabit to fit new store iterator interface
This commit is contained in:
parent
bf0bef058d
commit
e643f36fa3
2 changed files with 16 additions and 7 deletions
|
@ -131,7 +131,8 @@ impl HabitTemplate for Entry {
|
||||||
let iter = self
|
let iter = self
|
||||||
.get_internal_links()?
|
.get_internal_links()?
|
||||||
.map(|link| link.get_store_id().clone())
|
.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));
|
let sidi = StoreIdIterator::new(Box::new(iter));
|
||||||
Ok(HabitInstanceStoreIdIterator::new(sidi))
|
Ok(HabitInstanceStoreIdIterator::new(sidi))
|
||||||
|
|
|
@ -22,16 +22,21 @@ use libimagstore::storeid::StoreIdIteratorWithStore;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
|
|
||||||
use util::IsHabitCheck;
|
use util::IsHabitCheck;
|
||||||
|
use error::Result;
|
||||||
|
use error::HabitError as HE;
|
||||||
|
|
||||||
pub struct HabitTemplateStoreIdIterator(StoreIdIterator);
|
pub struct HabitTemplateStoreIdIterator(StoreIdIterator);
|
||||||
|
|
||||||
impl Iterator for HabitTemplateStoreIdIterator {
|
impl Iterator for HabitTemplateStoreIdIterator {
|
||||||
type Item = StoreId;
|
type Item = Result<StoreId>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
while let Some(n) = self.0.next() {
|
while let Some(n) = self.0.next() {
|
||||||
if n.is_habit_template() {
|
match n {
|
||||||
return Some(n)
|
Ok(n) => if n.is_habit_template() {
|
||||||
|
return Some(Ok(n))
|
||||||
|
},
|
||||||
|
Err(e) => return Some(Err(e).map_err(HE::from)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
@ -59,12 +64,15 @@ impl HabitInstanceStoreIdIterator {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Iterator for HabitInstanceStoreIdIterator {
|
impl Iterator for HabitInstanceStoreIdIterator {
|
||||||
type Item = StoreId;
|
type Item = Result<StoreId>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
while let Some(n) = self.0.next() {
|
while let Some(n) = self.0.next() {
|
||||||
if n.is_habit_instance() {
|
match n {
|
||||||
return Some(n)
|
Ok(n) => if n.is_habit_instance() {
|
||||||
|
return Some(Ok(n));
|
||||||
|
},
|
||||||
|
Err(e) => return Some(Err(e).map_err(HE::from)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
|
Loading…
Reference in a new issue