| 1 | //! # Manual Iterations |
| 2 | //! |
| 3 | //! Manually iterate over an `RRule`. |
| 4 | |
| 5 | use chronorust-analyzer cargo chrono 0.4.40 crate/::Datelikerust-analyzer cargo chrono 0.4.40 traits/Datelike#; |
| 6 | use rrulerust-analyzer cargo rrule 0.14.0 crate/::RRuleSetrust-analyzer cargo rrule 0.14.0 core/rruleset/RRuleSet#; |
| 7 | |
| 8 | fn mainrust-analyzer cargo rrule 0.14.0 main().() { |
| 9 | let rrule: RRuleSetrust-analyzer cargo rrule 0.14.0 core/rruleset/RRuleSet# = "DTSTART;TZID=America/New_York:20200902T130000\n\ |
| 10 | RRULE:FREQ=Weekly" |
| 11 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 12 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("The RRule is not valid"); |
| 13 | |
| 14 | let iter = rrule.into_iterrust-analyzer cargo rrule 0.14.0 iter/rruleset_iter/impl#[`&RRuleSet`][IntoIterator]into_iter().(); |
| 15 | |
| 16 | // Or: |
| 17 | // |
| 18 | // let iter: RRuleSetIter = "DTSTART;TZID=America/New_York:20200902T130000\n\ |
| 19 | // RRULE:FREQ=Weekly" |
| 20 | // .parse() |
| 21 | // .expect("The RRule is not valid"); |
| 22 | // |
| 23 | |
| 24 | for next in iter.takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(50) { |
| 25 | if next.yearrust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`][Datelike]year().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().2021 { |
| 26 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("These are all the weeks before 2021."); |
| 27 | break; |
| 28 | } |
| 29 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Date: {}", next.to_rfc3339rust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`]to_rfc3339().()); |
| 30 | } |
| 31 | } |