pub struct Cron { /* private fields */ }Expand description
A cron-like recurrence pattern.
You can imagine this as some more granular form of the the cron pattern * * * * * (at
every minute). Cron also includes a 6th component to facilitate second precision.
The default value of a Cron produces an event at every second, which would be equivalent to
the second-enhanced cron pattern of * * * * * *.
After constructed, this type has various builder methods like .second()
and .hours() to configure the details of the cron pattern.
§Example: once per day at a certain time
// Every day at 12:30.
let pattern = Cron::new().hour(12).minute(30);§Example: at multiple occasion thoughout the day
// Every day at 12:30, 13:30 and 14:30.
let pattern = Cron::new().hours(12..15).minute(30);§Example: multiple non-consecutive time units
// Every day at 10:30 and 20:30.
let pattern = Cron::new().hour(10).hour(20).minute(30);
// Or
let pattern = Cron::new().hours([10, 20]).minute(30);§Example: pitfalls
Because Cron behaves pretty much like a cron pattern, the following is expected behaviour
but might not be what you want.
// This ticks at 10:15 and 20:30. But it also ticks at 10:30 and 20:15.
let pattern = Cron::new()
.hour(10).minute(15)
.hour(20).minute(30);
// And so does this.
let pattern = Cron::new().hours([10, 20]).minutes([15, 30]);
// Let's break it down:
let pattern = Cron::new()
.hour(10) // Tick at hour 10.
.minute(15) // Tick at minute 15.
.hour(20) // Tick at hour 20 (we already tick at 10 too).
.minute(30); // Tick at minute 30 (we already tick at 15 too).
// This ticks every day at:
//
// - On hour 10 at minute 15 and 30
// - On hour 20 at minute 15 and 30§Example: time unit ranges
// This ticks at every hour from 10 to 19 at every minute from 15 to 29 in european summer
// months:
let pattern = Cron::new().months(6..=9).hours(10..=20).minutes(15..30);Implementations§
Source§impl Cron
impl Cron
Sourcepub fn year(self, year: i16) -> Cron
pub fn year(self, year: i16) -> Cron
Limit the pattern to a specific year.
This method can be called multiple times to limit the pattern to multiple different
years. Alternatively, you can use .years() to feed years from an
iterator.
The fallible version of this method is Cron::try_year.
§Panics
This panics when the year is too small or too big. The minimum value is -9999. The
maximum value is 9999.
Sourcepub fn year_step_by(self, start: i16, step: usize) -> Cron
pub fn year_step_by(self, start: i16, step: usize) -> Cron
Limit the years in the pattern to every step’s year from start onwards.
The fallible version of this method is Cron::try_year_step_by.
§Panics
The method will panic if the given step is 0 or if start is too small or too big. The
minimum start value is -9999. The maximum start value is 9999.
Sourcepub fn years<I: IntoIterator<Item = i16>>(self, years: I) -> Cron
pub fn years<I: IntoIterator<Item = i16>>(self, years: I) -> Cron
Limit the years in the pattern to specific values from an iterator.
The fallible version of this method is Cron::try_years.
§Panics
This panics when any of the year values produced by the iterator is year is too small
or too big. The minimum value is -9999. The maximum value is 9999.
Sourcepub fn month(self, month: i8) -> Cron
pub fn month(self, month: i8) -> Cron
Limit the pattern to a specific month.
This method can be called multiple times to limit the pattern to multiple different
months. Alternatively, you can use .months() to feed months from an
iterator.
The fallible version of this method is Cron::try_month.
§Panics
This panics when the month is too small or too big. The minimum value is 1. The maximum
value is 12.
Sourcepub fn month_step_by(self, start: i8, step: usize) -> Cron
pub fn month_step_by(self, start: i8, step: usize) -> Cron
Limit the months in the pattern to every step’s month from start onwards.
The fallible version of this method is Cron::try_month_step_by.
§Panics
The method will panic if the given step is 0 or if start is too small or too big. The
minimum start value is 1. The maximum start value is 12.
Sourcepub fn months<I: IntoIterator<Item = i8>>(self, months: I) -> Cron
pub fn months<I: IntoIterator<Item = i8>>(self, months: I) -> Cron
Limit the months in the pattern to specific values from an iterator.
The fallible version of this method is Cron::try_months.
§Panics
This panics when any of the month values produced by the iterator is month is too small
or too big. The minimum value is 1. The maximum value is 12.
Sourcepub fn weekday(self, weekday: Weekday) -> Cron
pub fn weekday(self, weekday: Weekday) -> Cron
Limit the pattern to a specific weekday.
This method can be called multiple times to limit the pattern to multiple different
weekdays. Alternatively, you can use .weekdays() to feed weekdays
from an iterator.
Sourcepub fn weekday_step_by(self, start: Weekday, step: usize) -> Cron
pub fn weekday_step_by(self, start: Weekday, step: usize) -> Cron
Limit the weekdays in the pattern to every step’s weekday from start onwards.
§Panics
The method will panic if the given step is 0.
Sourcepub fn weekdays<I: IntoIterator<Item = Weekday>>(self, weekdays: I) -> Cron
pub fn weekdays<I: IntoIterator<Item = Weekday>>(self, weekdays: I) -> Cron
Limit the weekdays in the pattern to specific values from an iterator.
Sourcepub fn day(self, day: i8) -> Cron
pub fn day(self, day: i8) -> Cron
Limit the pattern to a specific day.
This method can be called multiple times to limit the pattern to multiple different days.
Alternatively, you can use .days() to feed days from an iterator.
The fallible version of this method is Cron::try_day.
§Panics
This panics when the day is too small or too big. The minimum value is 1. The maximum
value is 31.
Sourcepub fn day_step_by(self, start: i8, step: usize) -> Cron
pub fn day_step_by(self, start: i8, step: usize) -> Cron
Limit the days in the pattern to every step’s day from start onwards.
The fallible version of this method is Cron::try_day_step_by.
§Panics
The method will panic if the given step is 0 or if start is too small or too big. The
minimum start value is 1. The maximum start value is 31.
Sourcepub fn days<I: IntoIterator<Item = i8>>(self, days: I) -> Cron
pub fn days<I: IntoIterator<Item = i8>>(self, days: I) -> Cron
Limit the days in the pattern to specific values from an iterator.
The fallible version of this method is Cron::try_days.
§Panics
This panics when any of the day values produced by the iterator is day is too small
or too big. The minimum value is 1. The maximum value is 31.
Sourcepub fn hour(self, hour: i8) -> Cron
pub fn hour(self, hour: i8) -> Cron
Limit the pattern to a specific hour.
This method can be called multiple times to limit the pattern to multiple different hours.
Alternatively, you can use .hours() to feed hours from an iterator.
The fallible version of this method is Cron::try_hour.
§Panics
This panics when the hour is too small or too big. The minimum value is 0. The maximum
value is 23.
Sourcepub fn hour_step_by(self, start: i8, step: usize) -> Cron
pub fn hour_step_by(self, start: i8, step: usize) -> Cron
Limit the hours in the pattern to every step’s hour from start onwards.
The fallible version of this method is Cron::try_hour_step_by.
§Panics
The method will panic if the given step is 0 or if start is too small or too big. The
minimum start value is 0. The maximum start value is 23.
Sourcepub fn hours<I: IntoIterator<Item = i8>>(self, hours: I) -> Cron
pub fn hours<I: IntoIterator<Item = i8>>(self, hours: I) -> Cron
Limit the hours in the pattern to specific values from an iterator.
The fallible version of this method is Cron::try_hours.
§Panics
This panics when any of the hour values produced by the iterator is hour is too small
or too big. The minimum value is 0. The maximum value is 23.
Sourcepub fn minute(self, minute: i8) -> Cron
pub fn minute(self, minute: i8) -> Cron
Limit the pattern to a specific minute.
This method can be called multiple times to limit the pattern to multiple different minutes.
Alternatively, you can use .minutes() to feed minutes from an iterator.
The fallible version of this method is Cron::try_minute.
§Panics
This panics when the minute is too small or too big. The minimum value is 0. The maximum
value is 59.
Sourcepub fn minute_step_by(self, start: i8, step: usize) -> Cron
pub fn minute_step_by(self, start: i8, step: usize) -> Cron
Limit the minutes in the pattern to every step’s minute from start onwards.
The fallible version of this method is Cron::try_minute_step_by.
§Panics
The method will panic if the given step is 0 or if start is too small or too big. The
minimum start value is 0. The maximum start value is 59.
Sourcepub fn minutes<I: IntoIterator<Item = i8>>(self, minutes: I) -> Cron
pub fn minutes<I: IntoIterator<Item = i8>>(self, minutes: I) -> Cron
Limit the minutes in the pattern to specific values from an iterator.
The fallible version of this method is Cron::try_minutes.
§Panics
This panics when any of the minute values produced by the iterator is minute is too small
or too big. The minimum value is 0. The maximum value is 59.
Sourcepub fn second(self, second: i8) -> Cron
pub fn second(self, second: i8) -> Cron
Limit the pattern to a specific second.
This method can be called multiple times to limit the pattern to multiple different seconds.
Alternatively, you can use .seconds() to feed seconds from an iterator.
The fallible version of this method is Cron::try_second.
§Panics
This panics when the second is too small or too big. The minimum value is 0. The maximum
value is 59.
Sourcepub fn second_step_by(self, start: i8, step: usize) -> Cron
pub fn second_step_by(self, start: i8, step: usize) -> Cron
Limit the seconds in the pattern to every step’s second from start onwards.
The fallible version of this method is Cron::try_second_step_by.
§Panics
The method will panic if the given step is 0 or if start is too small or too big. The
minimum start value is 0. The maximum start value is 59.
Sourcepub fn seconds<I: IntoIterator<Item = i8>>(self, seconds: I) -> Cron
pub fn seconds<I: IntoIterator<Item = i8>>(self, seconds: I) -> Cron
Limit the seconds in the pattern to specific values from an iterator.
The fallible version of this method is Cron::try_seconds.
§Panics
This panics when any of the second values produced by the iterator is second is too small
or too big. The minimum value is 0. The maximum value is 59.
Source§impl Cron
impl Cron
Sourcepub fn try_year(self, year: i16) -> Result<Cron, Error>
pub fn try_year(self, year: i16) -> Result<Cron, Error>
Limit the pattern to a specific year.
This method can be called multiple times to limit the pattern to multiple different years.
Alternatively, you can use .try_years() to feed years from an
iterator.
The panicking version of this method is Cron::year.
§Errors
This returns an error when the year is too small or too big. The minimum value is -9999.
The maximum value is 9999.
Sourcepub fn try_year_step_by(self, start: i16, step: usize) -> Result<Cron, Error>
pub fn try_year_step_by(self, start: i16, step: usize) -> Result<Cron, Error>
Limit the years in the pattern to every step’s year from start onwards.
§Errors
The returns an error if the given step is 0 or if start is too small or too big. The
minimum start value is -9999. The maximum start value is 9999.
The panicking version of this method is Cron::year_step_by.
§Panics
The method will panic if the given step is 0.
Sourcepub fn try_years<I: IntoIterator<Item = i16>>(
self,
years: I,
) -> Result<Cron, Error>
pub fn try_years<I: IntoIterator<Item = i16>>( self, years: I, ) -> Result<Cron, Error>
Limit the years in the pattern to specific values from an iterator.
The panicking version of this method is Cron::years.
§Errors
This returns an error when any of the year values produced by the iterator is too small or
too big. The minimum value is -9999. The maximum value is 9999.
Sourcepub fn try_month(self, month: i8) -> Result<Cron, Error>
pub fn try_month(self, month: i8) -> Result<Cron, Error>
Limit the pattern to a specific month.
This method can be called multiple times to limit the pattern to multiple different months.
Alternatively, you can use .months() to feed months from an iterator.
The panicking version of this method is Cron::month.
§Errors
This returns an error when the month is too small or too big. The minimum value is 1.
The maximum value is 12.
Sourcepub fn try_month_step_by(self, start: i8, step: usize) -> Result<Cron, Error>
pub fn try_month_step_by(self, start: i8, step: usize) -> Result<Cron, Error>
Limit the months in the pattern to every step’s month from start onwards.
The panicking version of this method is Cron::month_step_by.
§Errors
The returns an error if the given step is 0 or if start is too small or too big. The
minimum start value is 1. The maximum start value is 12.
§Panics
The method will panic if the given step is 0.
Sourcepub fn try_months<I: IntoIterator<Item = i8>>(
self,
months: I,
) -> Result<Cron, Error>
pub fn try_months<I: IntoIterator<Item = i8>>( self, months: I, ) -> Result<Cron, Error>
Limit the months in the pattern to specific values from an iterator.
The panicking version of this method is Cron::months.
§Errors
This returns an error when any of the month values produced by the iterator is month is
too small or too big. The minimum value is 1. The maximum value is 12.
Sourcepub fn try_day(self, day: i8) -> Result<Cron, Error>
pub fn try_day(self, day: i8) -> Result<Cron, Error>
Limit the pattern to a specific day.
This method can be called multiple times to limit the pattern to multiple different days.
Alternatively, you can use .days() to feed days from an iterator.
The panicking version of this method is Cron::day.
§Errors
This returns an error when the day is too small or too big. The minimum value is 1.
The maximum value is 31.
Sourcepub fn try_day_step_by(self, start: i8, step: usize) -> Result<Cron, Error>
pub fn try_day_step_by(self, start: i8, step: usize) -> Result<Cron, Error>
Limit the days in the pattern to every step’s day from start onwards.
The panicking version of this method is Cron::day_step_by.
§Errors
The returns an error if the given step is 0 or if start is too small or too big. The
minimum start value is 1. The maximum start value is 31.
§Panics
The method will panic if the given step is 0.
Sourcepub fn try_days<I: IntoIterator<Item = i8>>(
self,
days: I,
) -> Result<Cron, Error>
pub fn try_days<I: IntoIterator<Item = i8>>( self, days: I, ) -> Result<Cron, Error>
Limit the days in the pattern to specific values from an iterator.
The panicking version of this method is Cron::days.
§Errors
This returns an error when any of the day values produced by the iterator is day is
too small or too big. The minimum value is 1. The maximum value is 31.
Sourcepub fn try_hour(self, hour: i8) -> Result<Cron, Error>
pub fn try_hour(self, hour: i8) -> Result<Cron, Error>
Limit the pattern to a specific hour.
The panicking version of this method is Cron::hour.
This method can be called multiple times to limit the pattern to multiple different hours.
Alternatively, you can use .hours() to feed hours from an iterator.
§Errors
This returns an error when the hour is too small or too big. The minimum value is 0.
The maximum value is 23.
Sourcepub fn try_hour_step_by(self, start: i8, step: usize) -> Result<Cron, Error>
pub fn try_hour_step_by(self, start: i8, step: usize) -> Result<Cron, Error>
Limit the hours in the pattern to every step’s hour from start onwards.
The panicking version of this method is Cron::hour_step_by.
§Errors
The returns an error if the given step is 0 or if start is too small or too big. The
minimum start value is 0. The maximum start value is 23.
§Panics
The method will panic if the given step is 0.
Sourcepub fn try_hours<I: IntoIterator<Item = i8>>(
self,
hours: I,
) -> Result<Cron, Error>
pub fn try_hours<I: IntoIterator<Item = i8>>( self, hours: I, ) -> Result<Cron, Error>
Limit the hours in the pattern to specific values from an iterator.
The panicking version of this method is Cron::hours.
§Errors
This returns an error when any of the hour values produced by the iterator is hour is
too small or too big. The minimum value is 0. The maximum value is 23.
Sourcepub fn try_minute(self, minute: i8) -> Result<Cron, Error>
pub fn try_minute(self, minute: i8) -> Result<Cron, Error>
Limit the pattern to a specific minute.
This method can be called multiple times to limit the pattern to multiple different minutes.
Alternatively, you can use .minutes() to feed minutes from an iterator.
The panicking version of this method is Cron::minute.
§Errors
This returns an error when the minute is too small or too big. The minimum value is 0.
The maximum value is 59.
Sourcepub fn try_minute_step_by(self, start: i8, step: usize) -> Result<Cron, Error>
pub fn try_minute_step_by(self, start: i8, step: usize) -> Result<Cron, Error>
Limit the minutes in the pattern to every step’s minute from start onwards.
The panicking version of this method is Cron::minute_step_by.
§Errors
The returns an error if the given step is 0 or if start is too small or too big. The
minimum start value is 0. The maximum start value is 59.
§Panics
The method will panic if the given step is 0.
Sourcepub fn try_minutes<I: IntoIterator<Item = i8>>(
self,
minutes: I,
) -> Result<Cron, Error>
pub fn try_minutes<I: IntoIterator<Item = i8>>( self, minutes: I, ) -> Result<Cron, Error>
Limit the minutes in the pattern to specific values from an iterator.
The panicking version of this method is Cron::minutes.
§Errors
This returns an error when any of the minute values produced by the iterator is minute is
too small or too big. The minimum value is 0. The maximum value is 59.
Sourcepub fn try_second(self, second: i8) -> Result<Cron, Error>
pub fn try_second(self, second: i8) -> Result<Cron, Error>
Limit the pattern to a specific second.
This method can be called multiple times to limit the pattern to multiple different seconds.
Alternatively, you can use .seconds() to feed seconds from an iterator.
The panicking version of this method is Cron::second.
§Errors
This returns an error when the second is too small or too big. The minimum value is 0.
The maximum value is 59.
Sourcepub fn try_second_step_by(self, start: i8, step: usize) -> Result<Cron, Error>
pub fn try_second_step_by(self, start: i8, step: usize) -> Result<Cron, Error>
Limit the seconds in the pattern to every step’s second from start onwards.
The panicking version of this method is Cron::second_step_by.
§Errors
The returns an error if the given step is 0 or if start is too small or too big. The
minimum start value is 0. The maximum start value is 59.
§Panics
The method will panic if the given step is 0.
Sourcepub fn try_seconds<I: IntoIterator<Item = i8>>(
self,
seconds: I,
) -> Result<Cron, Error>
pub fn try_seconds<I: IntoIterator<Item = i8>>( self, seconds: I, ) -> Result<Cron, Error>
Limit the seconds in the pattern to specific values from an iterator.
The panicking version of this method is Cron::seconds.
§Errors
This returns an error when any of the second values produced by the iterator is second is
too small or too big. The minimum value is 0. The maximum value is 59.