summaryrefslogtreecommitdiffstats
path: root/libimagmail
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-10-04 14:19:36 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-10-12 19:17:41 +0200
commit0250a2c66259f147962ec40cbf86bfb5de04c886 (patch)
treea2d36d2ea8e2494ef9b9465813c6e041987463ab /libimagmail
parentaf54e621a83cfadb63569f63f722301c60661168 (diff)
Add MailIter
Diffstat (limited to 'libimagmail')
-rw-r--r--libimagmail/src/iter.rs37
-rw-r--r--libimagmail/src/lib.rs1
2 files changed, 38 insertions, 0 deletions
diff --git a/libimagmail/src/iter.rs b/libimagmail/src/iter.rs
new file mode 100644
index 00000000..365a0928
--- /dev/null
+++ b/libimagmail/src/iter.rs
@@ -0,0 +1,37 @@
+//! Module for the MailIter
+//!
+//! MailIter is a iterator which takes an Iterator that yields `Ref` and yields itself
+//! `Result<Mail>`, where `Err(_)` is returned if the Ref is not a Mail or parsing of the
+//! referenced mail file failed.
+//!
+
+use mail::Mail;
+use result::Result;
+
+use libimagref::reference::Ref;
+
+use std::marker::PhantomData;
+
+struct MailIter<'a, I: 'a + Iterator<Item = Ref<'a>>> {
+ _marker: PhantomData<&'a I>,
+ i: I,
+}
+
+impl<'a, I: Iterator<Item = Ref<'a>>> MailIter<'a, I> {
+
+ pub fn new(i: I) -> MailIter<'a, I> {
+ MailIter { _marker: PhantomData, i: i }
+ }
+
+}
+
+impl<'a, I: Iterator<Item = Ref<'a>>> Iterator for MailIter<'a, I> {
+
+ type Item = Result<Mail<'a>>;
+
+ fn next(&mut self) -> Option<Result<Mail<'a>>> {
+ self.i.next().map(Mail::from_ref)
+ }
+
+}
+
diff --git a/libimagmail/src/lib.rs b/libimagmail/src/lib.rs
index e4db2f4f..1d88a069 100644
--- a/libimagmail/src/lib.rs
+++ b/libimagmail/src/lib.rs
@@ -10,6 +10,7 @@ extern crate libimagref;
pub mod error;
pub mod hasher;
+pub mod iter;
pub mod mail;
pub mod result;