Refactor libimagentryannotation to fit new store iterator interface
This commit is contained in:
parent
40688a3c2d
commit
6f81d02445
2 changed files with 17 additions and 13 deletions
|
@ -92,7 +92,7 @@ impl Annotateable for Entry {
|
|||
fn annotations<'a>(&self, store: &'a Store) -> Result<AnnotationIter<'a>> {
|
||||
self.get_internal_links()
|
||||
.map_err(From::from)
|
||||
.map(|iter| StoreIdIterator::new(Box::new(iter.map(|e| e.get_store_id().clone()))))
|
||||
.map(|iter| StoreIdIterator::new(Box::new(iter.map(|e| e.get_store_id().clone()).map(Ok))))
|
||||
.map(|i| AnnotationIter::new(i, store))
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ use libimagstore::store::FileLockEntry;
|
|||
use libimagstore::storeid::StoreIdIterator;
|
||||
|
||||
use error::Result;
|
||||
use error::AnnotationError as AE;
|
||||
use error::AnnotationErrorKind as AEK;
|
||||
use error::ResultExt;
|
||||
|
||||
|
@ -43,8 +44,12 @@ impl<'a> Iterator for AnnotationIter<'a> {
|
|||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
loop {
|
||||
match self.0.next().map(|id| self.1.get(id)) {
|
||||
Some(Ok(Some(entry))) => {
|
||||
match self.0.next() {
|
||||
None => return None, // iterator consumed
|
||||
Some(Err(e)) => return Some(Err(e).map_err(AE::from)),
|
||||
Some(Ok(id)) => match self.1.get(id) {
|
||||
Err(e) => return Some(Err(e).chain_err(|| AEK::StoreReadError)),
|
||||
Ok(Some(entry)) => {
|
||||
match entry.get_header().read_bool("annotation.is_annotation").chain_err(|| AEK::HeaderReadError) {
|
||||
Ok(None) => continue, // not an annotation
|
||||
Ok(Some(false)) => continue,
|
||||
|
@ -52,9 +57,8 @@ impl<'a> Iterator for AnnotationIter<'a> {
|
|||
Err(e) => return Some(Err(e)),
|
||||
}
|
||||
},
|
||||
Some(Ok(None)) => continue,
|
||||
Some(Err(e)) => return Some(Err(e).chain_err(|| AEK::StoreReadError)),
|
||||
None => return None, // iterator consumed
|
||||
Ok(None) => continue,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue