diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-10-17 13:51:40 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-10-19 14:34:11 +0200 |
commit | d54666894d15e9a56503b23eaf6f8dce28579ecc (patch) | |
tree | e1415687a74716fb827eb705674e4c1756812b63 /libimagentrylink | |
parent | c55ad42e5908183bc7c09f07e9fa5a1946ff557d (diff) |
Add FilterMoreThanIter
Diffstat (limited to 'libimagentrylink')
-rw-r--r-- | libimagentrylink/src/internal.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/libimagentrylink/src/internal.rs b/libimagentrylink/src/internal.rs index db75269b..b2060af7 100644 --- a/libimagentrylink/src/internal.rs +++ b/libimagentrylink/src/internal.rs @@ -134,6 +134,10 @@ pub mod iter { FilterLessThanIter(self, n) } + pub fn with_more_than_n_links(self, n: usize) -> FilterMoreThanIter<'a> { + FilterMoreThanIter(self, n) + } + pub fn store(&self) -> &Store { self.1 } @@ -194,6 +198,48 @@ pub mod iter { } + /// An iterator that removes all Items from the iterator that have `less than` `N` links. + /// This does _not_ `Store::delete()` anything. + pub struct FilterMoreThanIter<'a>(GetIter<'a>, usize); + + impl<'a> FilterMoreThanIter<'a> { + + /// Create a new `FilterNLinksIter` iterator that filters out all entries that have LESS + /// THAN N links + pub fn new(gi: GetIter<'a>, n: usize) -> FilterNLinksIter<'a> { + FilterNLinksIter(gi, n) + } + } + + impl<'a> Iterator for FilterMoreThanIter<'a> { + type Item = Result<FileLockEntry<'a>>; + + fn next(&mut self) -> Option<Self::Item> { + use internal::InternalLinker; + + loop { + match self.0.next() { + Some(Ok(fle)) => { + let links = match fle.get_internal_links().map_err_into(LEK::StoreReadError) + { + Err(e) => return Some(Err(e)), + Ok(links) => links, + }; + if links.count() < self.1 { + continue; + } else { + return Some(Ok(fle)); + } + }, + Some(Err(e)) => return Some(Err(e)), + None => break, + } + } + None + } + + } + /// An iterator that removes all Items from the iterator that are not linked anymore by calling /// `Store::delete()` on them. /// |