Refactor libimagentrycategory to fit new store iterator interface
This commit is contained in:
parent
6f81d02445
commit
6ee3f4a3f6
2 changed files with 35 additions and 25 deletions
|
@ -55,7 +55,7 @@ impl Category for Entry {
|
|||
|
||||
fn get_entries<'a>(&self, store: &'a Store) -> Result<CategoryEntryIterator<'a>> {
|
||||
trace!("Getting linked entries for category '{:?}'", self.get_location());
|
||||
let sit = self.get_internal_links()?.map(|l| l.get_store_id().clone());
|
||||
let sit = self.get_internal_links()?.map(|l| l.get_store_id().clone()).map(Ok);
|
||||
let sit = StoreIdIterator::new(Box::new(sit));
|
||||
let name = self.get_name()?;
|
||||
Ok(CategoryEntryIterator::new(store, sit, name))
|
||||
|
|
|
@ -60,18 +60,23 @@ impl<'a> Iterator for CategoryNameIter<'a> {
|
|||
let query = CATEGORY_REGISTER_NAME_FIELD_PATH;
|
||||
|
||||
while let Some(sid) = self.1.next() {
|
||||
if sid.is_in_collection(&["category"]) {
|
||||
let func = |store: &Store| { // hack for returning Some(Result<_, _>)
|
||||
store
|
||||
.get(sid)?
|
||||
.ok_or_else(|| CE::from_kind(CEK::StoreReadError))?
|
||||
.get_header()
|
||||
.read_string(query)
|
||||
.chain_err(|| CEK::HeaderReadError)?
|
||||
.ok_or_else(|| CE::from_kind(CEK::StoreReadError))
|
||||
};
|
||||
match sid {
|
||||
Err(e) => return Some(Err(e).map_err(CE::from)),
|
||||
Ok(sid) => {
|
||||
if sid.is_in_collection(&["category"]) {
|
||||
let func = |store: &Store| { // hack for returning Some(Result<_, _>)
|
||||
store
|
||||
.get(sid)?
|
||||
.ok_or_else(|| CE::from_kind(CEK::StoreReadError))?
|
||||
.get_header()
|
||||
.read_string(query)
|
||||
.chain_err(|| CEK::HeaderReadError)?
|
||||
.ok_or_else(|| CE::from_kind(CEK::StoreReadError))
|
||||
};
|
||||
|
||||
return Some(func(&self.0))
|
||||
return Some(func(&self.0))
|
||||
}
|
||||
},
|
||||
} // else continue
|
||||
}
|
||||
|
||||
|
@ -92,20 +97,25 @@ impl<'a> Iterator for CategoryEntryIterator<'a> {
|
|||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
while let Some(next) = self.1.next() {
|
||||
let getter = |next| -> Result<(String, FileLockEntry<'a>)> {
|
||||
let entry = self.0
|
||||
.get(next)?
|
||||
.ok_or_else(|| CE::from_kind(CEK::StoreReadError))?;
|
||||
Ok((entry.get_category()?, entry))
|
||||
};
|
||||
match next {
|
||||
Err(e) => return Some(Err(e).map_err(CE::from)),
|
||||
Ok(next) => {
|
||||
let getter = |next| -> Result<(String, FileLockEntry<'a>)> {
|
||||
let entry = self.0
|
||||
.get(next)?
|
||||
.ok_or_else(|| CE::from_kind(CEK::StoreReadError))?;
|
||||
Ok((entry.get_category()?, entry))
|
||||
};
|
||||
|
||||
match getter(next) {
|
||||
Err(e) => return Some(Err(e)),
|
||||
Ok((c, e)) => {
|
||||
if c == self.2 {
|
||||
return Some(Ok(e))
|
||||
// } else {
|
||||
// continue
|
||||
match getter(next) {
|
||||
Err(e) => return Some(Err(e)),
|
||||
Ok((c, e)) => {
|
||||
if c == self.2 {
|
||||
return Some(Ok(e))
|
||||
// } else {
|
||||
// continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue