From 3b01a9eb2fc34af47a1b789b08d96c231ac05cab Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 28 Jan 2018 21:21:44 +0100 Subject: [PATCH] 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`. --- lib/core/libimagstore/src/iter.rs | 6 +++++ lib/core/libimagstore/src/storeid.rs | 38 ++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/lib/core/libimagstore/src/iter.rs b/lib/core/libimagstore/src/iter.rs index d42c92fc..67c0f0ba 100644 --- a/lib/core/libimagstore/src/iter.rs +++ b/lib/core/libimagstore/src/iter.rs @@ -34,6 +34,12 @@ macro_rules! mk_iterator { pub struct $itername<'a>(Box>, &'a Store); + impl<'a> $itername<'a> { + pub fn new(inner: Box>, store: &'a Store) -> Self { + $itername(inner, store) + } + } + impl<'a> Iterator for $itername<'a> { type Item = Result<$yield>; diff --git a/lib/core/libimagstore/src/storeid.rs b/lib/core/libimagstore/src/storeid.rs index 1585d754..04e80099 100644 --- a/lib/core/libimagstore/src/storeid.rs +++ b/lib/core/libimagstore/src/storeid.rs @@ -32,6 +32,11 @@ use error::ResultExt; use store::Result; use store::Store; +use iter::create::StoreCreateIterator; +use iter::delete::StoreDeleteIterator; +use iter::get::StoreGetIterator; +use iter::retrieve::StoreRetrieveIterator; + /// The Index into the Store #[derive(Debug, Clone, Hash, Eq, PartialOrd, Ord)] pub struct StoreId { @@ -280,13 +285,42 @@ impl<'a> Iterator for StoreIdIteratorWithStore<'a> { } impl<'a> StoreIdIteratorWithStore<'a> { + pub fn new(iter: Box>, store: &'a Store) -> Self { StoreIdIteratorWithStore(StoreIdIterator::new(iter), store) } - pub fn get_store(&self) -> &Store { - &self.1 + /// Transform the iterator into a StoreCreateIterator + /// + /// 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)]