From 8520fe52226d3586f9b4d7ece968f9bbf6450d0c Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 26 Sep 2017 17:03:17 +0200 Subject: Add IntoCalculatingIter trait for calling calculate() on all iterators --- src/iter.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/iter.rs') diff --git a/src/iter.rs b/src/iter.rs index 4bfc2ca..821c9db 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -47,10 +47,6 @@ impl Iter { self.base -= self.increment.clone(); } - pub fn calculate(self) -> CalculatingIter { - CalculatingIter::new(self) - } - } /// # Warning @@ -78,13 +74,17 @@ impl Iterator for Iter { pub struct CalculatingIter(I) where I: Iterator; -impl> CalculatingIter { +impl CalculatingIter + where I: Iterator +{ pub fn new(i: I) -> CalculatingIter { CalculatingIter(i) } } -impl> Iterator for CalculatingIter { +impl Iterator for CalculatingIter + where I: Iterator +{ type Item = Result; fn next(&mut self) -> Option { @@ -93,6 +93,18 @@ impl> Iterator for CalculatingIter { } +pub trait IntoCalculatingIter : Iterator + Sized { + fn calculate(self) -> CalculatingIter; +} + +impl IntoCalculatingIter for I + where I: Iterator +{ + fn calculate(self) -> CalculatingIter { + CalculatingIter(self) + } +} + pub mod extensions { use timetype::TimeType as TT; use super::Iter; @@ -234,6 +246,7 @@ pub mod extensions { use super::*; use timetype::TimeType as TT; use chrono::NaiveDate as ND; + use iter::IntoCalculatingIter; fn ymd_hms(y: i32, m: u32, d: u32, h: u32, mi: u32, s: u32) -> TT { TT::moment(ND::from_ymd(y, m, d).and_hms(h, mi, s)) -- cgit v1.2.3