| 1 | use craterust-analyzer cargo rrule 0.14.0 crate/::{NWeekdayrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#, RRulerust-analyzer cargo rrule 0.14.0 core/rrule/RRule#}; |
| 2 | |
| 3 | use superrust-analyzer cargo rrule 0.14.0 iter/::iterinforust-analyzer cargo rrule 0.14.0 iter/iterinfo/::IterInforust-analyzer cargo rrule 0.14.0 iter/iterinfo/IterInfo#; |
| 4 | |
| 5 | type RRuleFilterrust-analyzer cargo rrule 0.14.0 iter/filters/RRuleFilter# = &'static dyn Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&IterInforust-analyzer cargo rrule 0.14.0 iter/iterinfo/IterInfo#, usize, &RRulerust-analyzer cargo rrule 0.14.0 core/rrule/RRule#) -> bool; |
| 6 | |
| 7 | const FILTERSrust-analyzer cargo rrule 0.14.0 iter/filters/FILTERS.: [RRuleFilterrust-analyzer cargo rrule 0.14.0 iter/filters/RRuleFilter#; 7] = [ |
| 8 | &is_filtered_by_monthrust-analyzer cargo rrule 0.14.0 iter/filters/is_filtered_by_month()., |
| 9 | &is_filtered_by_week_numberrust-analyzer cargo rrule 0.14.0 iter/filters/is_filtered_by_week_number()., |
| 10 | &is_filtered_by_weekdayrust-analyzer cargo rrule 0.14.0 iter/filters/is_filtered_by_weekday()., |
| 11 | &is_filtered_by_neg_weekdayrust-analyzer cargo rrule 0.14.0 iter/filters/is_filtered_by_neg_weekday()., |
| 12 | &is_filtered_by_easterrust-analyzer cargo rrule 0.14.0 iter/filters/is_filtered_by_easter()., |
| 13 | &is_filtered_by_month_dayrust-analyzer cargo rrule 0.14.0 iter/filters/is_filtered_by_month_day()., |
| 14 | &is_filtered_by_year_dayrust-analyzer cargo rrule 0.14.0 iter/filters/is_filtered_by_year_day()., |
| 15 | ]; |
| 16 | |
| 17 | pub(craterust-analyzer cargo rrule 0.14.0 crate/) fn is_filteredrust-analyzer cargo rrule 0.14.0 iter/filters/is_filtered().(ii: &IterInforust-analyzer cargo rrule 0.14.0 iter/iterinfo/IterInfo#, current_day: usize) -> bool { |
| 18 | let rrule = ii.rrulerust-analyzer cargo rrule 0.14.0 iter/iterinfo/impl#[IterInfo]rrule().(); |
| 19 | FILTERSrust-analyzer cargo rrule 0.14.0 iter/filters/FILTERS. |
| 20 | .into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/iter/impl#[`[T; N]`][IntoIterator]into_iter().() |
| 21 | .anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|filter| filter(ii, current_day, rrule)) |
| 22 | } |
| 23 | |
| 24 | fn is_filtered_by_monthrust-analyzer cargo rrule 0.14.0 iter/filters/is_filtered_by_month().(ii: &IterInforust-analyzer cargo rrule 0.14.0 iter/iterinfo/IterInfo#, current_day: usize, rrule: &RRulerust-analyzer cargo rrule 0.14.0 core/rrule/RRule#) -> bool { |
| 25 | if rrule.by_monthrust-analyzer cargo rrule 0.14.0 core/rrule/RRule#by_month..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 26 | return false; |
| 27 | } |
| 28 | |
| 29 | let current_month = ii.month_maskrust-analyzer cargo rrule 0.14.0 iter/iterinfo/impl#[IterInfo]month_mask().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().current_day]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 30 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().rrule.by_monthrust-analyzer cargo rrule 0.14.0 core/rrule/RRule#by_month..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(¤t_month) |
| 31 | } |
| 32 | |
| 33 | fn is_filtered_by_week_numberrust-analyzer cargo rrule 0.14.0 iter/filters/is_filtered_by_week_number().(ii: &IterInforust-analyzer cargo rrule 0.14.0 iter/iterinfo/IterInfo#, current_day: usize, rrule: &RRulerust-analyzer cargo rrule 0.14.0 core/rrule/RRule#) -> bool { |
| 34 | if rrule.by_week_norust-analyzer cargo rrule 0.14.0 core/rrule/RRule#by_week_no..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(ii.week_no_maskrust-analyzer cargo rrule 0.14.0 iter/iterinfo/impl#[IterInfo]week_no_mask().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(week_no_mask) if week_no_mask[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().current_day]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). == 0) |
| 39 | } |
| 40 | |
| 41 | fn is_filtered_by_weekdayrust-analyzer cargo rrule 0.14.0 iter/filters/is_filtered_by_weekday().(ii: &IterInforust-analyzer cargo rrule 0.14.0 iter/iterinfo/IterInfo#, current_day: usize, rrule: &RRulerust-analyzer cargo rrule 0.14.0 core/rrule/RRule#) -> bool { |
| 42 | let mut by_weekday_every_week_only = rrule |
| 43 | .by_weekdayrust-analyzer cargo rrule 0.14.0 core/rrule/RRule#by_weekday. |
| 44 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 45 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|by_weekday| match by_weekday { |
| 46 | // Get only `Every` occurrences. |
| 47 | NWeekdayrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#::Everyrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#Every#(weekday) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(weekday.num_days_from_mondayrust-analyzer cargo chrono 0.4.40 weekday/impl#[Weekday]num_days_from_monday().()), |
| 48 | NWeekdayrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#::Nthrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#Nth#(_, _) => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 49 | }) |
| 50 | .peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().(); |
| 51 | |
| 52 | // Check if empty |
| 53 | if by_weekday_every_week_only.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() { |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | let current_weekday = ii.weekday_maskrust-analyzer cargo rrule 0.14.0 iter/iterinfo/impl#[IterInfo]weekday_mask().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().current_day]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 58 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().by_weekday_every_week_only.anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|el| el rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().current_weekday) |
| 59 | } |
| 60 | |
| 61 | fn is_filtered_by_neg_weekdayrust-analyzer cargo rrule 0.14.0 iter/filters/is_filtered_by_neg_weekday().(ii: &IterInforust-analyzer cargo rrule 0.14.0 iter/iterinfo/IterInfo#, current_day: usize, _rrule: &RRulerust-analyzer cargo rrule 0.14.0 core/rrule/RRule#) -> bool { |
| 62 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(neg_weekday_mask) = ii.neg_weekday_maskrust-analyzer cargo rrule 0.14.0 iter/iterinfo/impl#[IterInfo]neg_weekday_mask().() { |
| 63 | if neg_weekday_mask.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | let current_neg_weekday = neg_weekday_mask[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().current_day]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 68 | current_neg_weekday rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0 |
| 69 | } else { |
| 70 | false |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | fn is_filtered_by_easterrust-analyzer cargo rrule 0.14.0 iter/filters/is_filtered_by_easter().(ii: &IterInforust-analyzer cargo rrule 0.14.0 iter/iterinfo/IterInfo#, current_day: usize, rrule: &RRulerust-analyzer cargo rrule 0.14.0 core/rrule/RRule#) -> bool { |
| 75 | if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(feature = "by-easter") { |
| 76 | if rrule.by_easterrust-analyzer cargo rrule 0.14.0 core/rrule/RRule#by_easter..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() { |
| 77 | return false; |
| 78 | } |
| 79 | match i32::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[i32][`TryFrom<usize>`]try_from().(current_day) { |
| 80 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(current_day) => { |
| 81 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(ii.easter_maskrust-analyzer cargo rrule 0.14.0 iter/iterinfo/impl#[IterInfo]easter_mask().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(easter_mask) if easter_mask.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(¤t_day)) |
| 82 | } |
| 83 | _ => true, |
| 84 | } |
| 85 | } else { |
| 86 | false |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | fn is_filtered_by_month_dayrust-analyzer cargo rrule 0.14.0 iter/filters/is_filtered_by_month_day().(ii: &IterInforust-analyzer cargo rrule 0.14.0 iter/iterinfo/IterInfo#, current_day: usize, rrule: &RRulerust-analyzer cargo rrule 0.14.0 core/rrule/RRule#) -> bool { |
| 91 | if rrule.by_month_dayrust-analyzer cargo rrule 0.14.0 core/rrule/RRule#by_month_day..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() && rrule.by_n_month_dayrust-analyzer cargo rrule 0.14.0 core/rrule/RRule#by_n_month_day..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | let current_month_day = ii.month_day_maskrust-analyzer cargo rrule 0.14.0 iter/iterinfo/impl#[IterInfo]month_day_mask().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().current_day]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 96 | let current_n_month_day = ii.neg_month_day_maskrust-analyzer cargo rrule 0.14.0 iter/iterinfo/impl#[IterInfo]neg_month_day_mask().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().current_day]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 97 | let filtered_by_month_day = !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().rrule.by_month_dayrust-analyzer cargo rrule 0.14.0 core/rrule/RRule#by_month_day..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(¤t_month_day); |
| 98 | let filtered_by_n_month_day = !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().rrule.by_n_month_dayrust-analyzer cargo rrule 0.14.0 core/rrule/RRule#by_n_month_day..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(¤t_n_month_day); |
| 99 | |
| 100 | filtered_by_month_day && filtered_by_n_month_day |
| 101 | } |
| 102 | |
| 103 | fn is_filtered_by_year_dayrust-analyzer cargo rrule 0.14.0 iter/filters/is_filtered_by_year_day().(ii: &IterInforust-analyzer cargo rrule 0.14.0 iter/iterinfo/IterInfo#, current_day: usize, rrule: &RRulerust-analyzer cargo rrule 0.14.0 core/rrule/RRule#) -> bool { |
| 104 | if rrule.by_year_dayrust-analyzer cargo rrule 0.14.0 core/rrule/RRule#by_year_day..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 105 | return false; |
| 106 | } |
| 107 | |
| 108 | let current_day = match i16::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[i16][`TryFrom<usize>`]try_from().(current_day) { |
| 109 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(current_day) => current_day, |
| 110 | _ => return true, |
| 111 | }; |
| 112 | |
| 113 | let year_len = i16::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[i16][`TryFrom<u16>`]try_from().(ii.year_lenrust-analyzer cargo rrule 0.14.0 iter/iterinfo/impl#[IterInfo]year_len().()).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("year length is always within range of i16"); |
| 114 | let next_year_len = |
| 115 | i16::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[i16][`TryFrom<u16>`]try_from().(ii.next_year_lenrust-analyzer cargo rrule 0.14.0 iter/iterinfo/impl#[IterInfo]next_year_len().()).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("year length is always within range of i16"); |
| 116 | |
| 117 | if current_day rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]lt().year_len { |
| 118 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().rrule.by_year_dayrust-analyzer cargo rrule 0.14.0 core/rrule/RRule#by_year_day..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&(current_day rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().1)) |
| 119 | && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().rrule.by_year_dayrust-analyzer cargo rrule 0.14.0 core/rrule/RRule#by_year_day..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&(current_day rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().year_len)) |
| 120 | } else { |
| 121 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().rrule.by_year_dayrust-analyzer cargo rrule 0.14.0 core/rrule/RRule#by_year_day..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&(current_day rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().year_len)) |
| 122 | && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().rrule |
| 123 | .by_year_dayrust-analyzer cargo rrule 0.14.0 core/rrule/RRule#by_year_day. |
| 124 | .containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&(current_day rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().next_year_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().year_len)) |
| 125 | } |
| 126 | } |