diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index c4d08326..db9eac3f 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -25,7 +25,7 @@ use walkdir::Iter as WalkDirIter; use error::{ParserErrorKind, ParserError}; use error::{StoreError, StoreErrorKind}; -use storeid::{IntoStoreId, StoreId, StoreIdIterator}; +use storeid::{IntoStoreId, StoreId, GlobStoreIdIterator, StoreIdIterator}; use lazyfile::LazyFile; use hook::aspect::Aspect; @@ -361,7 +361,7 @@ impl Store { let path = [ path, "/*" ].join(""); debug!("glob()ing with '{}'", path); glob(&path[..]) - .map(StoreIdIterator::new) + .map(|paths| StoreIdIterator::new(Box::new(GlobStoreIdIterator::new(paths)))) .map_err(|e| StoreError::new(StoreErrorKind::GlobError, Some(Box::new(e)))) } else { Err(StoreError::new(StoreErrorKind::EncodingError, None)) diff --git a/libimagstore/src/storeid.rs b/libimagstore/src/storeid.rs index d5229e2b..cdcf1676 100644 --- a/libimagstore/src/storeid.rs +++ b/libimagstore/src/storeid.rs @@ -155,10 +155,41 @@ macro_rules! module_entry_path_mod { ) } -pub struct StoreIdIterator { +pub struct GlobStoreIdIterator { paths: Paths, } +impl Debug for GlobStoreIdIterator { + + fn fmt(&self, fmt: &mut Formatter) -> RResult<(), FmtError> { + write!(fmt, "GlobStoreIdIterator") + } + +} + +impl GlobStoreIdIterator { + + pub fn new(paths: Paths) -> GlobStoreIdIterator { + GlobStoreIdIterator { + paths: paths, + } + } + +} + +impl Iterator for GlobStoreIdIterator { + type Item = StoreId; + + fn next(&mut self) -> Option { + self.paths.next().and_then(|o| o.ok()).map(|p| StoreId::from(p)) + } + +} + +pub struct StoreIdIterator { + iter: Box>, +} + impl Debug for StoreIdIterator { fn fmt(&self, fmt: &mut Formatter) -> RResult<(), FmtError> { @@ -169,9 +200,9 @@ impl Debug for StoreIdIterator { impl StoreIdIterator { - pub fn new(paths: Paths) -> StoreIdIterator { + pub fn new(iter: Box>) -> StoreIdIterator { StoreIdIterator { - paths: paths, + iter: iter, } } @@ -181,7 +212,7 @@ impl Iterator for StoreIdIterator { type Item = StoreId; fn next(&mut self) -> Option { - self.paths.next().and_then(|o| o.ok()).map(|p| StoreId::from(p)) + self.iter.next() } }