summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/iter.rs25
1 files changed, 19 insertions, 6 deletions
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<Self> {
- CalculatingIter::new(self)
- }
-
}
/// # Warning
@@ -78,13 +74,17 @@ impl Iterator for Iter {
pub struct CalculatingIter<I>(I)
where I: Iterator<Item = TimeType>;
-impl<I: Iterator<Item = TimeType>> CalculatingIter<I> {
+impl<I> CalculatingIter<I>
+ where I: Iterator<Item = TimeType>
+{
pub fn new(i: I) -> CalculatingIter<I> {
CalculatingIter(i)
}
}
-impl<I: Iterator<Item = TimeType>> Iterator for CalculatingIter<I> {
+impl<I> Iterator for CalculatingIter<I>
+ where I: Iterator<Item = TimeType>
+{
type Item = Result<TimeType>;
fn next(&mut self) -> Option<Self::Item> {
@@ -93,6 +93,18 @@ impl<I: Iterator<Item = TimeType>> Iterator for CalculatingIter<I> {
}
+pub trait IntoCalculatingIter : Iterator<Item = TimeType> + Sized {
+ fn calculate(self) -> CalculatingIter<Self>;
+}
+
+impl<I> IntoCalculatingIter for I
+ where I: Iterator<Item = TimeType>
+{
+ fn calculate(self) -> CalculatingIter<Self> {
+ 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))