Rewrite to not use Store::retrieve_for_module()

This commit is contained in:
Matthias Beyer 2018-04-24 14:01:40 +02:00
parent 2c52957b63
commit 5666ef12d0
3 changed files with 13 additions and 9 deletions

View File

@ -134,9 +134,9 @@ impl Diary for Store {
/// Get all diary names
fn diary_names(&self) -> Result<DiaryNameIterator> {
self.retrieve_for_module("diary")
.chain_err(|| DEK::StoreReadError)
.map(DiaryNameIterator::new)
self.entries()
.map(|it| DiaryNameIterator::new(it.without_store()))
.map_err(::error::DiaryError::from)
}
}

View File

@ -23,6 +23,7 @@ error_chain! {
}
links {
StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind);
EntryUtilError(::libimagentryutil::error::EntryUtilError, ::libimagentryutil::error::EntryUtilErrorKind);
}

View File

@ -140,18 +140,21 @@ impl Iterator for DiaryNameIterator {
type Item = Result<String>;
fn next(&mut self) -> Option<Self::Item> {
self.0
.next()
.map(|s| {
s.to_str()
while let Some(next) = self.0.next() {
if next.is_in_collection(&["diary"]) {
return Some(next
.to_str()
.chain_err(|| DEK::DiaryNameFindingError)
.and_then(|s| {
s.split("diary/")
.nth(1)
.and_then(|n| n.split("/").nth(0).map(String::from))
.ok_or(DE::from_kind(DEK::DiaryNameFindingError))
})
})
}))
}
}
None
}
}