Debian Codegraph @

examples/manual_rrule.rs

raw symbols SCIP
1 //! # Manual [`RRule`]
2 //!
3 //! Create an [`RRule`] object.
4
5 use chronorust-analyzer cargo chrono 0.4.40 crate/::{Datelikerust-analyzer cargo chrono 0.4.40 traits/Datelike#, TimeZonerust-analyzer cargo chrono 0.4.40 offset/TimeZone#, Timelikerust-analyzer cargo chrono 0.4.40 traits/Timelike#};
6 use rrulerust-analyzer cargo rrule 0.14.0 crate/::{Frequencyrust-analyzer cargo rrule 0.14.0 core/rrule/Frequency#, RRulerust-analyzer cargo rrule 0.14.0 core/rrule/RRule#, Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#};
7
8 fn mainrust-analyzer cargo rrule 0.14.0 main().() {
9 // Build an RRuleSet that starts the first day in 2020 at 9:00AM and occurs daily 5 times
10 let start_date = Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#::UTCrust-analyzer cargo rrule 0.14.0 core/timezone/impl#[Tz]UTC..with_ymd_and_hmsrust-analyzer cargo chrono 0.4.40 offset/TimeZone#with_ymd_and_hms().(2020, 1, 1, 9, 0, 0).unwraprust-analyzer cargo chrono 0.4.40 offset/impl#[`LocalResult<T>`]unwrap().();
11 let rrule_set = RRulerust-analyzer cargo rrule 0.14.0 core/rrule/RRule#::defaultrust-analyzer cargo rrule 0.14.0 core/rrule/impl#[`RRule<Unvalidated>`][Default]default().()
12 .countrust-analyzer cargo rrule 0.14.0 core/rrule/impl#[`RRule<Unvalidated>`]count().(5)
13 .freqrust-analyzer cargo rrule 0.14.0 core/rrule/impl#[`RRule<Unvalidated>`]freq().(Frequencyrust-analyzer cargo rrule 0.14.0 core/rrule/Frequency#::Dailyrust-analyzer cargo rrule 0.14.0 core/rrule/Frequency#Daily#)
14 .buildrust-analyzer cargo rrule 0.14.0 core/rrule/impl#[`RRule<Unvalidated>`]build().(start_date)
15 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("RRule invalid");
16
17 let recurrences = rrule_set.all_uncheckedrust-analyzer cargo rrule 0.14.0 core/rruleset/impl#[RRuleSet]all_unchecked().();
18 for (i, rec) in recurrences.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
19 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rec.yearrust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`][Datelike]year().(), 2020);
20 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rec.monthrust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`][Datelike]month().(), 1);
21 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rec.dayrust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`][Datelike]day().(), 1 +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). i as u32);
22 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rec.hourrust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`][Timelike]hour().(), 9);
23 }
24 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recurrences.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 5);
25 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Done, everything worked.");
26 }