summaryrefslogtreecommitdiffstats
path: root/src/iter.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-09-26 17:03:17 +0200
committerMatthias Beyer <mail@beyermatthias.de>2017-09-26 17:11:26 +0200
commit8520fe52226d3586f9b4d7ece968f9bbf6450d0c (patch)
tree041f9be887ced214e85fedca447fad209d53e131 /src/iter.rs
parent79923c0cd6ed917b3b0463a66d0a44df85165e23 (diff)
Add IntoCalculatingIter trait for calling calculate() on all iterators
Diffstat (limited to 'src/iter.rs')
-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))