diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2019-01-05 01:04:21 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-02-15 20:53:29 +0100 |
commit | b4f401675e159e9173109390ff3409d338635548 (patch) | |
tree | 1f6210aacdd107bb5cebf5223335f977d951b27e /lib | |
parent | 2e7c17d5dc535e7ca7db1353fe8c788c4ab31be1 (diff) |
Add Entries::into_storeid_iter()
This is a more complicated functionality (implementation-wise) of the
`Entries` iterator, which allows a callee to transform it into a
`StoreIdIterator`.
It uses the crate internal `PathIterator` type and a function to extract
the internals of that iterator which is then turned into an iterator
over `Result<StoreId>`, which can be used to build a `StoreIdIterator`.
The implementation is ugly, but we need to be able to transform a
`Entries` iterator into a `StoreIdIterator` in the
`libimagentryannotation`, and possibly in more cases where we want to be
agnostic over iterators.
Maybe there is a cleaner solution to this, hence the comment about
whether this should be removed.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/core/libimagstore/src/file_abstraction/iter.rs | 12 | ||||
-rw-r--r-- | lib/core/libimagstore/src/iter.rs | 17 |
2 files changed, 25 insertions, 4 deletions
diff --git a/lib/core/libimagstore/src/file_abstraction/iter.rs b/lib/core/libimagstore/src/file_abstraction/iter.rs index 5ef5d386..2eda4c27 100644 --- a/lib/core/libimagstore/src/file_abstraction/iter.rs +++ b/lib/core/libimagstore/src/file_abstraction/iter.rs @@ -71,6 +71,18 @@ impl<'a> PathIterator<'a> { self } + /// Turn iterator into its internals + /// + /// Used for `Entries::into_storeid_iter()` + /// + /// # TODO + /// + /// Revisit whether this can be done in a cleaner way. See commit message for why this is + /// needed. + pub(crate) fn into_inner(self) -> Box<Iterator<Item = Result<PathBuf>>> { + self.iter + } + } impl<'a> Iterator for PathIterator<'a> { diff --git a/lib/core/libimagstore/src/iter.rs b/lib/core/libimagstore/src/iter.rs index e236d984..9ab6ed36 100644 --- a/lib/core/libimagstore/src/iter.rs +++ b/lib/core/libimagstore/src/iter.rs @@ -138,6 +138,7 @@ mod compile_test { } use storeid::StoreId; +use storeid::StoreIdIterator; use self::delete::StoreDeleteIterator; use self::get::StoreGetIterator; use self::retrieve::StoreRetrieveIterator; @@ -178,10 +179,18 @@ impl<'a> Entries<'a> { Entries(self.0.in_collection(c), self.1) } - // TODO: Remove or fix me - //pub fn without_store(self) -> StoreIdIterator { - // StoreIdIterator::new(Box::new(self.0.map(|r| r.map(|id| id.without_base())))) - //} + /// 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 /// |