From 0250a2c66259f147962ec40cbf86bfb5de04c886 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 4 Oct 2016 14:19:36 +0200 Subject: [PATCH] Add MailIter --- libimagmail/src/iter.rs | 37 +++++++++++++++++++++++++++++++++++++ libimagmail/src/lib.rs | 1 + 2 files changed, 38 insertions(+) create mode 100644 libimagmail/src/iter.rs 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`, 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>> { + _marker: PhantomData<&'a I>, + i: I, +} + +impl<'a, I: Iterator>> MailIter<'a, I> { + + pub fn new(i: I) -> MailIter<'a, I> { + MailIter { _marker: PhantomData, i: i } + } + +} + +impl<'a, I: Iterator>> Iterator for MailIter<'a, I> { + + type Item = Result>; + + fn next(&mut self) -> Option>> { + 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;