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>
This commit is contained in:
parent
2e7c17d5dc
commit
b4f401675e
2 changed files with 25 additions and 4 deletions
|
@ -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> {
|
||||
|
|
|
@ -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
|
||||
///
|
||||
|
|
Loading…
Reference in a new issue