summaryrefslogtreecommitdiffstats
path: root/libimagentrylink
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-10-17 13:49:56 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-10-19 14:34:11 +0200
commitc55ad42e5908183bc7c09f07e9fa5a1946ff557d (patch)
tree1151edb9d25efb96b925682ee90bb6b6d052366f /libimagentrylink
parent1e008f26a2fa05184773e7723cc9ef5bd7527c66 (diff)
Rewrite FilterUnlinkedIter to a FilterLessThanIter
Diffstat (limited to 'libimagentrylink')
-rw-r--r--libimagentrylink/src/internal.rs28
1 files changed, 20 insertions, 8 deletions
diff --git a/libimagentrylink/src/internal.rs b/libimagentrylink/src/internal.rs
index e89a3c10..db75269b 100644
--- a/libimagentrylink/src/internal.rs
+++ b/libimagentrylink/src/internal.rs
@@ -125,9 +125,13 @@ pub mod iter {
DeleteUnlinkedIter(self)
}
- /// Turn this iterator into a FilterUnlinkedIter, which filters out the unlinked entries.
- pub fn without_unlinked(self) -> FilterUnlinkedIter<'a> {
- FilterUnlinkedIter(self)
+ /// Turn this iterator into a FilterLessThanIter, which filters out the unlinked entries.
+ pub fn without_unlinked(self) -> FilterLessThanIter<'a> {
+ FilterLessThanIter(self, 1)
+ }
+
+ pub fn with_less_than_n_links(self, n: usize) -> FilterLessThanIter<'a> {
+ FilterLessThanIter(self, n)
}
pub fn store(&self) -> &Store {
@@ -148,11 +152,20 @@ pub mod iter {
}
- /// An iterator that removes all Items from the iterator that are not linked anymore.
+ /// An iterator that removes all Items from the iterator that have `less than` `N` links.
/// This does _not_ `Store::delete()` anything.
- pub struct FilterUnlinkedIter<'a>(GetIter<'a>);
+ pub struct FilterLessThanIter<'a>(GetIter<'a>, usize);
+
+ impl<'a> FilterLessThanIter<'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 FilterUnlinkedIter<'a> {
+ impl<'a> Iterator for FilterLessThanIter<'a> {
type Item = Result<FileLockEntry<'a>>;
fn next(&mut self) -> Option<Self::Item> {
@@ -166,7 +179,7 @@ pub mod iter {
Err(e) => return Some(Err(e)),
Ok(links) => links,
};
- if links.count() == 0 {
+ if links.count() > self.1 {
continue;
} else {
return Some(Ok(fle));
@@ -181,7 +194,6 @@ pub mod iter {
}
-
/// An iterator that removes all Items from the iterator that are not linked anymore by calling
/// `Store::delete()` on them.
///