summaryrefslogtreecommitdiffstats
path: root/lib/core/libimagstore/src/iter.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/core/libimagstore/src/iter.rs')
-rw-r--r--lib/core/libimagstore/src/iter.rs29
1 files changed, 19 insertions, 10 deletions
diff --git a/lib/core/libimagstore/src/iter.rs b/lib/core/libimagstore/src/iter.rs
index 1639b02c..2e895b78 100644
--- a/lib/core/libimagstore/src/iter.rs
+++ b/lib/core/libimagstore/src/iter.rs
@@ -167,11 +167,11 @@ use failure::Fallible as Result;
///
/// Functionality to exclude subdirectories is not possible with the current implementation and has
/// to be done during iteration, with filtering (as usual).
-pub struct Entries<'a>(PathIterator, &'a Store);
+pub struct Entries<'a>(PathIterator<'a>, &'a Store);
impl<'a> Entries<'a> {
- pub(crate) fn new(pi: PathIterator, store: &'a Store) -> Self {
+ pub(crate) fn new(pi: PathIterator<'a>, store: &'a Store) -> Self {
Entries(pi, store)
}
@@ -179,29 +179,38 @@ impl<'a> Entries<'a> {
Entries(self.0.in_collection(c), self.1)
}
- pub fn without_store(self) -> StoreIdIterator {
- StoreIdIterator::new(Box::new(self.0))
+ /// Turn `Entries` iterator into generic `StoreIdIterator`
+ ///
+ /// # TODO
+ ///
+ /// Revisit whether this can be done in a cleaner way. See commit message for why this is
+ /// needed.
+ pub fn into_storeid_iter(self) -> StoreIdIterator {
+ let iter = self.0
+ .into_inner()
+ .map(|r| r.and_then(StoreId::new));
+ StoreIdIterator::new(Box::new(iter))
}
/// Transform the iterator into a StoreDeleteIterator
///
/// This immitates the API from `libimagstore::iter`.
pub fn into_delete_iter(self) -> StoreDeleteIterator<'a> {
- StoreDeleteIterator::new(Box::new(self.0), self.1)
+ StoreDeleteIterator::new(Box::new(self.0.map(|r| r.map(|id| id.without_base()))), self.1)
}
/// Transform the iterator into a StoreGetIterator
///
/// This immitates the API from `libimagstore::iter`.
pub fn into_get_iter(self) -> StoreGetIterator<'a> {
- StoreGetIterator::new(Box::new(self.0), self.1)
+ StoreGetIterator::new(Box::new(self.0.map(|r| r.map(|id| id.without_base()))), self.1)
}
/// Transform the iterator into a StoreRetrieveIterator
///
/// This immitates the API from `libimagstore::iter`.
pub fn into_retrieve_iter(self) -> StoreRetrieveIterator<'a> {
- StoreRetrieveIterator::new(Box::new(self.0), self.1)
+ StoreRetrieveIterator::new(Box::new(self.0.map(|r| r.map(|id| id.without_base()))), self.1)
}
}
@@ -210,7 +219,7 @@ impl<'a> Iterator for Entries<'a> {
type Item = Result<StoreId>;
fn next(&mut self) -> Option<Self::Item> {
- self.0.next()
+ self.0.next().map(|r| r.map(|id| id.without_base()))
}
}
@@ -227,7 +236,7 @@ mod tests {
use store::Store;
use storeid::StoreId;
- use file_abstraction::InMemoryFileAbstraction;
+ use file_abstraction::inmemory::InMemoryFileAbstraction;
use libimagutil::variants::generate_variants;
pub fn get_store() -> Store {
@@ -244,7 +253,7 @@ mod tests {
let base = String::from("entry");
let variants = vec!["coll_1", "coll_2", "coll_3"];
let modifier = |base: &String, v: &&str| {
- StoreId::new(Some(store.path().clone()), PathBuf::from(format!("{}/{}", *v, base))).unwrap()
+ StoreId::new(PathBuf::from(format!("{}/{}", *v, base))).unwrap()
};
generate_variants(&base, variants.iter(), &modifier)