Rewrite all_category_names() for removed Store::retrieve_for_module()

This commit is contained in:
Matthias Beyer 2018-04-22 13:35:35 +02:00
parent 255f4211c9
commit 007c02c2f1

View file

@ -101,9 +101,7 @@ impl CategoryRegister for Store {
/// Get all category names /// Get all category names
fn all_category_names(&self) -> Result<CategoryNameIter> { fn all_category_names(&self) -> Result<CategoryNameIter> {
self.retrieve_for_module("category") Ok(CategoryNameIter::new(self, self.entries()?.without_store()))
.chain_err(|| CEK::StoreReadError)
.map(|iter| CategoryNameIter::new(self, iter))
} }
/// Get a category by its name /// Get a category by its name
@ -268,18 +266,24 @@ impl<'a> Iterator for CategoryNameIter<'a> {
// TODO: Optimize me with lazy_static // TODO: Optimize me with lazy_static
let query = CATEGORY_REGISTER_NAME_FIELD_PATH; let query = CATEGORY_REGISTER_NAME_FIELD_PATH;
self.1 while let Some(sid) = self.1.next() {
.next() if sid.is_in_collection(&["category"]) {
.map(|sid| { let func = |store: &Store| { // hack for returning Some(Result<_, _>)
self.0 store
.get(sid)? .get(sid)?
.ok_or_else(|| CE::from_kind(CEK::StoreReadError))? .ok_or_else(|| CE::from_kind(CEK::StoreReadError))?
.get_header() .get_header()
.read_string(query) .read_string(query)
.chain_err(|| CEK::HeaderReadError)? .chain_err(|| CEK::HeaderReadError)?
.map(Category::from) .map(Category::from)
.ok_or_else(|| CE::from_kind(CEK::StoreReadError)) .ok_or_else(|| CE::from_kind(CEK::StoreReadError))
}) };
return Some(func(&self.0))
} // else continue
}
None
} }
} }