summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-10-26 20:23:00 +0200
committerMatthias Beyer <mail@beyermatthias.de>2019-10-26 20:48:00 +0200
commit0095dda99657f522d7bdbaaf25bc8ade79f3b0db (patch)
tree2827ec0aa2e2a3bfb4311b39707f389851701d7b
parentf1f7abddae6d250f61a18ddb210f59bf72b6214b (diff)
Add extension trait for iterator over Result<Entry>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--lib/core/libimagrt/src/iter.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/core/libimagrt/src/iter.rs b/lib/core/libimagrt/src/iter.rs
index 282570ad..c0d179c9 100644
--- a/lib/core/libimagrt/src/iter.rs
+++ b/lib/core/libimagrt/src/iter.rs
@@ -61,6 +61,46 @@ mod reporting {
}
+ pub trait ReportTouchedResultEntry<'a, I, D>
+ where I: Iterator<Item = Result<D>>,
+ D: Deref<Target = Entry>,
+ {
+ fn map_report_touched(self, rt: &'a Runtime) -> ReportTouchedResultEntryImpl<'a, I, D>;
+ }
+
+ impl<'a, I, D> ReportTouchedResultEntry<'a, I, D> for I
+ where I: Iterator<Item = Result<D>>,
+ D: Deref<Target = Entry>,
+ {
+ fn map_report_touched(self, rt: &'a Runtime) -> ReportTouchedResultEntryImpl<'a, I, D> {
+ ReportTouchedResultEntryImpl(self, rt)
+ }
+ }
+
+ pub struct ReportTouchedResultEntryImpl<'a, I, D>(I, &'a Runtime<'a>)
+ where I: Iterator<Item = Result<D>>,
+ D: Deref<Target = Entry>;
+
+ impl<'a, I, D> Iterator for ReportTouchedResultEntryImpl<'a, I, D>
+ where I: Iterator<Item = Result<D>>,
+ D: Deref<Target = Entry>,
+ {
+ type Item = Result<D>;
+
+ fn next(&mut self) -> Option<Self::Item> {
+ self.0.next()
+ .map(|r| {
+ r.and_then(|e| {
+ self.1
+ .report_touched(e.get_location())
+ .map_err(Error::from)
+ .map(|_| e)
+ })
+ })
+ }
+ }
+
+
pub trait ReportTouchedStoreId<'a, I>