iter.rs 817 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. //! Module for the MailIter
  2. //!
  3. //! MailIter is a iterator which takes an Iterator that yields `Ref` and yields itself
  4. //! `Result<Mail>`, where `Err(_)` is returned if the Ref is not a Mail or parsing of the
  5. //! referenced mail file failed.
  6. //!
  7. use mail::Mail;
  8. use result::Result;
  9. use libimagref::reference::Ref;
  10. use std::marker::PhantomData;
  11. struct MailIter<'a, I: 'a + Iterator<Item = Ref<'a>>> {
  12. _marker: PhantomData<&'a I>,
  13. i: I,
  14. }
  15. impl<'a, I: Iterator<Item = Ref<'a>>> MailIter<'a, I> {
  16. pub fn new(i: I) -> MailIter<'a, I> {
  17. MailIter { _marker: PhantomData, i: i }
  18. }
  19. }
  20. impl<'a, I: Iterator<Item = Ref<'a>>> Iterator for MailIter<'a, I> {
  21. type Item = Result<Mail<'a>>;
  22. fn next(&mut self) -> Option<Result<Mail<'a>>> {
  23. self.i.next().map(Mail::from_ref)
  24. }
  25. }