pub struct RecurrenceRule {
pub frequency: Frequency,
pub interval: u32,
pub weekdays: [bool; 7],
pub end: RecurrenceEnd,
}Expand description
A repeating schedule, starting from a date given when asking for its days. A date past the end of a shorter month falls on that month’s last day and returns to its own day after: the 31st is February 28, then March 31.
use ravenrs_widgets::{Date, Frequency, RecurrenceEnd, RecurrenceRule};
let start = Date::new(2026, 1, 31).unwrap();
let rule = RecurrenceRule::new(Frequency::Monthly).end(RecurrenceEnd::After(3));
let days = rule.occurrences(start, start, start.add_months(12));
assert_eq!(days, [start, Date::new(2026, 2, 28).unwrap(), Date::new(2026, 3, 31).unwrap()]);
// It can be stored as text, in the format of iCalendar.
assert_eq!(rule.to_text(), "FREQ=MONTHLY;COUNT=3");
assert_eq!(RecurrenceRule::parse(&rule.to_text()), Some(rule));Fields§
§frequency: FrequencyHow often.
interval: u32Every how many days, weeks, months or years; at least 1.
weekdays: [bool; 7]For weekly rules, the weekdays from Sunday to Saturday. With none chosen, the first day’s weekday.
end: RecurrenceEndWhen it stops.
Implementations§
Source§impl RecurrenceRule
impl RecurrenceRule
Sourcepub fn on_weekdays(self, days: impl IntoIterator<Item = u8>) -> Self
pub fn on_weekdays(self, days: impl IntoIterator<Item = u8>) -> Self
Sets the weekdays of a weekly rule, 0 = Sunday … 6 = Saturday.
Sourcepub fn end(self, end: RecurrenceEnd) -> Self
pub fn end(self, end: RecurrenceEnd) -> Self
Sets when it stops.
Sourcepub fn days_from(&self, start: Date) -> impl Iterator<Item = Date> + use<>
pub fn days_from(&self, start: Date) -> impl Iterator<Item = Date> + use<>
The days from start on, in order. It never ends by itself when the rule
does not, so limit it, as Self::occurrences does.
Sourcepub fn occurrences(&self, start: Date, from: Date, to: Date) -> Vec<Date>
pub fn occurrences(&self, start: Date, from: Date, to: Date) -> Vec<Date>
The days of a rule starting at start that fall in from..=to, in order.
Sourcepub fn parse(text: &str) -> Option<Self>
pub fn parse(text: &str) -> Option<Self>
Reads what Self::to_text writes; None when it is not a rule.
Trait Implementations§
Source§impl Clone for RecurrenceRule
impl Clone for RecurrenceRule
Source§fn clone(&self) -> RecurrenceRule
fn clone(&self) -> RecurrenceRule
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for RecurrenceRule
Source§impl Debug for RecurrenceRule
impl Debug for RecurrenceRule
Source§impl Default for RecurrenceRule
impl Default for RecurrenceRule
Source§impl Display for RecurrenceRule
impl Display for RecurrenceRule
impl Eq for RecurrenceRule
Source§impl Hash for RecurrenceRule
impl Hash for RecurrenceRule
Source§impl PartialEq for RecurrenceRule
impl PartialEq for RecurrenceRule
impl StructuralPartialEq for RecurrenceRule
Auto Trait Implementations§
impl Freeze for RecurrenceRule
impl RefUnwindSafe for RecurrenceRule
impl Send for RecurrenceRule
impl Sync for RecurrenceRule
impl Unpin for RecurrenceRule
impl UnsafeUnpin for RecurrenceRule
impl UnwindSafe for RecurrenceRule
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Brush for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more