summaryrefslogtreecommitdiffstats
path: root/libimagentrylink
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-10-17 09:25:41 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-10-19 14:34:11 +0200
commit1e008f26a2fa05184773e7723cc9ef5bd7527c66 (patch)
treeeb06712683486fc90f8c7a8df7a162b764616c80 /libimagentrylink
parent3e7f245278b38dae8dbc75d5609825166783c5b5 (diff)
Add FilterUnlinkedIter
Diffstat (limited to 'libimagentrylink')
-rw-r--r--libimagentrylink/src/internal.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/libimagentrylink/src/internal.rs b/libimagentrylink/src/internal.rs
index 3596d668..e89a3c10 100644
--- a/libimagentrylink/src/internal.rs
+++ b/libimagentrylink/src/internal.rs
@@ -125,6 +125,11 @@ 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)
+ }
+
pub fn store(&self) -> &Store {
self.1
}
@@ -143,10 +148,49 @@ pub mod iter {
}
+ /// An iterator that removes all Items from the iterator that are not linked anymore.
+ /// This does _not_ `Store::delete()` anything.
+ pub struct FilterUnlinkedIter<'a>(GetIter<'a>);
+
+ impl<'a> Iterator for FilterUnlinkedIter<'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() == 0 {
+ 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.
///
/// It yields only items which are somehow linked to another entry
+ ///
+ /// # Warning
+ ///
+ /// Deletes entries from the store.
+ ///
pub struct DeleteUnlinkedIter<'a>(GetIter<'a>);
impl<'a> Iterator for DeleteUnlinkedIter<'a> {