From cc8150e0a96f790363ec3400e8ec493b52dea1a8 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 26 Oct 2019 20:23:00 +0200 Subject: Add extension trait for iterator over Result Signed-off-by: Matthias Beyer --- lib/core/libimagrt/src/iter.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) 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>, + D: Deref, + { + 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>, + D: Deref, + { + 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>, + D: Deref; + + impl<'a, I, D> Iterator for ReportTouchedResultEntryImpl<'a, I, D> + where I: Iterator>, + D: Deref, + { + type Item = Result; + + fn next(&mut self) -> Option { + 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> -- cgit v1.2.3