diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2018-01-28 21:10:12 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2018-02-01 15:47:39 +0100 |
commit | 030e32e44f054519517c1d491f170b6687f848ba (patch) | |
tree | a3f252881e3dc90290ac3859f1a7bd984563015f | |
parent | da4b823048c91e30c8b4ed8eb2e3915fb29ce747 (diff) |
Provide StoreId Iterator which has a ref to the Store
This change is needed so we can refactor the "get" iterator to not take
an argument (the store) later, which improves the API.
-rw-r--r-- | bin/core/imag-diagnostics/src/main.rs | 1 | ||||
-rw-r--r-- | lib/core/libimagstore/src/store.rs | 7 | ||||
-rw-r--r-- | lib/core/libimagstore/src/storeid.rs | 29 |
3 files changed, 32 insertions, 5 deletions
diff --git a/bin/core/imag-diagnostics/src/main.rs b/bin/core/imag-diagnostics/src/main.rs index 7d3b06da..391bcfa1 100644 --- a/bin/core/imag-diagnostics/src/main.rs +++ b/bin/core/imag-diagnostics/src/main.rs @@ -45,7 +45,6 @@ use libimagrt::setup::generate_runtime_setup; use libimagerror::trace::MapErrTrace; use libimagstore::store::FileLockEntry; use libimagstore::storeid::StoreId; -use libimagstore::iter::get::StoreIdGetIteratorExtension; use libimagstore::error::StoreError as Error; use libimagentrylink::internal::*; diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index 365576e0..0a292ef2 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -40,7 +40,7 @@ use toml_query::read::TomlValueReadTypeExt; use error::{StoreError as SE, StoreErrorKind as SEK}; use error::ResultExt; -use storeid::{IntoStoreId, StoreId, StoreIdIterator}; +use storeid::{IntoStoreId, StoreId, StoreIdIterator, StoreIdIteratorWithStore}; use file_abstraction::FileAbstractionInstance; // We re-export the following things so tests can use them @@ -721,7 +721,7 @@ impl Store { } /// Get _all_ entries in the store (by id as iterator) - pub fn entries(&self) -> Result<StoreIdIterator> { + pub fn entries<'a>(&'a self) -> Result<StoreIdIteratorWithStore<'a>> { self.backend .pathes_recursively(self.path().clone()) .and_then(|iter| { @@ -738,9 +738,8 @@ impl Store { elems.push(sid); } } - Ok(StoreIdIterator::new(Box::new(elems.into_iter()))) + Ok(StoreIdIteratorWithStore::new(Box::new(elems.into_iter()), self)) }) - } /// Gets the path where this store is on the disk diff --git a/lib/core/libimagstore/src/storeid.rs b/lib/core/libimagstore/src/storeid.rs index dde25a2e..1585d754 100644 --- a/lib/core/libimagstore/src/storeid.rs +++ b/lib/core/libimagstore/src/storeid.rs @@ -30,6 +30,7 @@ use error::StoreErrorKind as SEK; use error::StoreError as SE; use error::ResultExt; use store::Result; +use store::Store; /// The Index into the Store #[derive(Debug, Clone, Hash, Eq, PartialOrd, Ord)] @@ -260,6 +261,34 @@ impl Iterator for StoreIdIterator { } +pub struct StoreIdIteratorWithStore<'a>(StoreIdIterator, &'a Store); + +impl<'a> Deref for StoreIdIteratorWithStore<'a> { + type Target = StoreIdIterator; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl<'a> Iterator for StoreIdIteratorWithStore<'a> { + type Item = StoreId; + + fn next(&mut self) -> Option<StoreId> { + self.0.next() + } +} + +impl<'a> StoreIdIteratorWithStore<'a> { + pub fn new(iter: Box<Iterator<Item = StoreId>>, store: &'a Store) -> Self { + StoreIdIteratorWithStore(StoreIdIterator::new(iter), store) + } + + pub fn get_store(&self) -> &Store { + &self.1 + } +} + #[cfg(test)] mod test { use std::path::PathBuf; |