Add API in StoreIdIteratorWithStore to get acting iterators
This patch adds API functions in the StoreIdIteratorWithStore iterator type to transform it into a iterator which _does_ something (as in the `libimagstore::iter` API). It mimics the API which is offered by `libimagstore::iter`.
This commit is contained in:
parent
030e32e44f
commit
3b01a9eb2f
2 changed files with 42 additions and 2 deletions
|
@ -34,6 +34,12 @@ macro_rules! mk_iterator {
|
||||||
|
|
||||||
pub struct $itername<'a>(Box<Iterator<Item = StoreId>>, &'a Store);
|
pub struct $itername<'a>(Box<Iterator<Item = StoreId>>, &'a Store);
|
||||||
|
|
||||||
|
impl<'a> $itername<'a> {
|
||||||
|
pub fn new(inner: Box<Iterator<Item = StoreId>>, store: &'a Store) -> Self {
|
||||||
|
$itername(inner, store)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> Iterator for $itername<'a> {
|
impl<'a> Iterator for $itername<'a> {
|
||||||
type Item = Result<$yield>;
|
type Item = Result<$yield>;
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,11 @@ use error::ResultExt;
|
||||||
use store::Result;
|
use store::Result;
|
||||||
use store::Store;
|
use store::Store;
|
||||||
|
|
||||||
|
use iter::create::StoreCreateIterator;
|
||||||
|
use iter::delete::StoreDeleteIterator;
|
||||||
|
use iter::get::StoreGetIterator;
|
||||||
|
use iter::retrieve::StoreRetrieveIterator;
|
||||||
|
|
||||||
/// The Index into the Store
|
/// The Index into the Store
|
||||||
#[derive(Debug, Clone, Hash, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Hash, Eq, PartialOrd, Ord)]
|
||||||
pub struct StoreId {
|
pub struct StoreId {
|
||||||
|
@ -280,13 +285,42 @@ impl<'a> Iterator for StoreIdIteratorWithStore<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> StoreIdIteratorWithStore<'a> {
|
impl<'a> StoreIdIteratorWithStore<'a> {
|
||||||
|
|
||||||
pub fn new(iter: Box<Iterator<Item = StoreId>>, store: &'a Store) -> Self {
|
pub fn new(iter: Box<Iterator<Item = StoreId>>, store: &'a Store) -> Self {
|
||||||
StoreIdIteratorWithStore(StoreIdIterator::new(iter), store)
|
StoreIdIteratorWithStore(StoreIdIterator::new(iter), store)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_store(&self) -> &Store {
|
/// Transform the iterator into a StoreCreateIterator
|
||||||
&self.1
|
///
|
||||||
|
/// This immitates the API from `libimagstore::iter`.
|
||||||
|
pub fn into_create_iter(self) -> StoreCreateIterator<'a> {
|
||||||
|
StoreCreateIterator::new(Box::new(self.0), self.1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in a new issue