From 975d283aae2ad70d6831d209700df9c0bc89a0a6 Mon Sep 17 00:00:00 2001 From: Fredrik Meringdal Date: Wed, 12 May 2021 18:16:11 +0200 Subject: good refactoring --- src/iter/iterinfo.rs | 8 ++++---- src/rrule.rs | 11 ++++------- src/rrule_iter.rs | 34 +++++++++++++++++++--------------- src/rruleset.rs | 11 ++++------- src/rruleset_iter.rs | 38 ++++++++++++++++++-------------------- 5 files changed, 49 insertions(+), 53 deletions(-) diff --git a/src/iter/iterinfo.rs b/src/iter/iterinfo.rs index 1a1a283..35b769f 100644 --- a/src/iter/iterinfo.rs +++ b/src/iter/iterinfo.rs @@ -5,15 +5,15 @@ use crate::iter::yearinfo::{rebuild_year, YearInfo}; use crate::options::{Frequenzy, ParsedOptions}; use chrono::prelude::*; -pub struct IterInfo { +pub struct IterInfo<'a> { pub yearinfo: Option, pub monthinfo: Option, pub eastermask: Option>, - pub options: ParsedOptions, + pub options: &'a ParsedOptions, } -impl IterInfo { - pub fn new(options: ParsedOptions) -> Self { +impl<'a> IterInfo<'a> { + pub fn new(options: &'a ParsedOptions) -> Self { let mut ii = Self { options, yearinfo: None, diff --git a/src/rrule.rs b/src/rrule.rs index 7ac6016..1d95fe9 100644 --- a/src/rrule.rs +++ b/src/rrule.rs @@ -16,15 +16,14 @@ impl RRule { /// Returns all the recurrences of the rrule pub fn all(&self) -> Vec> { - self.clone().into_iter().collect() + self.into_iter().collect() } /// Returns the last recurrence before the given datetime instance. /// The inc keyword defines what happens if dt is an recurrence. /// With inc == true, if dt itself is an recurrence, it will be returned. pub fn before(&self, dt: DateTime, inc: bool) -> Option> { - self.clone() - .into_iter() + self.into_iter() .take_while(|d| if inc { *d <= dt } else { *d < dt }) .last() } @@ -33,8 +32,7 @@ impl RRule { /// The inc keyword defines what happens if dt is an recurrence. /// With inc == true, if dt itself is an recurrence, it will be returned. pub fn after(&self, dt: DateTime, inc: bool) -> Option> { - self.clone() - .into_iter() + self.into_iter() .skip_while(|d| if inc { *d <= dt } else { *d < dt }) .next() } @@ -49,8 +47,7 @@ impl RRule { before: DateTime, inc: bool, ) -> Vec> { - self.clone() - .into_iter() + self.into_iter() .skip_while(|d| if inc { *d <= after } else { *d < after }) .take_while(|d| if inc { *d <= before } else { *d < before }) .collect() diff --git a/src/rrule_iter.rs b/src/rrule_iter.rs index 59f9cd7..27d5e90 100644 --- a/src/rrule_iter.rs +++ b/src/rrule_iter.rs @@ -4,30 +4,30 @@ use crate::iter::{ use crate::{datetime::from_ordinal, RRule}; use crate::{datetime::Time, Frequenzy}; use chrono::{prelude::*, Duration}; -use chrono_tz::Tz; -use chrono_tz::UTC; +use chrono_tz::{Tz, UTC}; use std::collections::VecDeque; const MAX_YEAR: i32 = 9999; -pub struct RRuleIter { +pub struct RRuleIter<'a> { pub counter_date: DateTime, - pub ii: IterInfo, + pub ii: IterInfo<'a>, pub timeset: Vec