summaryrefslogtreecommitdiff
path: root/src/iter_set.rs
diff options
context:
space:
mode:
authorFredrik Meringdal <fmeringdal@hotmail.com>2020-10-20 23:36:32 +0200
committerFredrik Meringdal <fmeringdal@hotmail.com>2020-10-20 23:36:32 +0200
commit8b062ddeb1143e6894653274a524b63dc7c5b165 (patch)
treef69b97e2876452569bb2f79527c0ef244421cab8 /src/iter_set.rs
parenteac4ef5fe5f0b86b576736ea49b53043c24c1357 (diff)
downloadrust_rrule-8b062ddeb1143e6894653274a524b63dc7c5b165.zip
checkpoint! Refactored more and tests pass
Diffstat (limited to 'src/iter_set.rs')
-rw-r--r--src/iter_set.rs20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/iter_set.rs b/src/iter_set.rs
index a8a7e48..9f251d9 100644
--- a/src/iter_set.rs
+++ b/src/iter_set.rs
@@ -9,10 +9,18 @@ use chrono::{DateTime, Duration, Utc};
use chrono_tz::*;
use std::collections::HashMap;
-pub fn iter_v2<F: FnMut(DateTime<Tz>, &mut IterResult) -> bool>(
- iter_result: &mut IterResult,
- options: &mut ParsedOptions,
- mut accept: F
+
+
+pub trait TIterResult {
+ fn accept(&mut self, date: DateTime<Tz>) -> bool;
+ fn get_value(&self) -> Vec<DateTime<Tz>>;
+}
+
+
+
+pub fn iter_v2<T: TIterResult>(
+ iter_result: &mut T,
+ options: &mut ParsedOptions
) -> Vec<DateTime<Tz>> {
if (options.count.is_some() && options.count.unwrap() == 0) || options.interval == 0 {
@@ -57,7 +65,7 @@ pub fn iter_v2<F: FnMut(DateTime<Tz>, &mut IterResult) -> bool>(
//let rezoned_date = rezone_if_needed(&res, &options);
let rezoned_date = UTC.timestamp(res.timestamp(), 0);
- if !accept(rezoned_date, iter_result) {
+ if !iter_result.accept(rezoned_date) {
return iter_result.get_value();
}
@@ -91,7 +99,7 @@ pub fn iter_v2<F: FnMut(DateTime<Tz>, &mut IterResult) -> bool>(
//let rezoned_date = rezone_if_needed(&res, &options);
let rezoned_date = UTC.timestamp(res.timestamp(), 0);
- if !accept(rezoned_date, iter_result) {
+ if !iter_result.accept(rezoned_date) {
return iter_result.get_value();
}
if count > 0 {