Cron

Struct Cron 

Source
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

Source

pub fn new() -> Cron

Create a new Cron that ticks every second.

Source§

impl Cron

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn weekdays<I: IntoIterator<Item = Weekday>>(self, weekdays: I) -> Cron

Limit the weekdays in the pattern to specific values from an iterator.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Cron

Source§

fn clone(&self) -> Cron

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Cron

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Cron

Source§

fn default() -> Cron

Returns the “default value” for a type. Read more
Source§

impl Pattern for Cron

Source§

fn next_after( &self, instant: DateTime, range: DateTimeRange, ) -> Option<DateTime>

Find the next DateTime after instant within a range. Read more
Source§

fn previous_before( &self, instant: DateTime, range: DateTimeRange, ) -> Option<DateTime>

Find the previous DateTime before instant within a range. Read more
Source§

fn closest_to( &self, instant: DateTime, range: DateTimeRange, ) -> Option<DateTime>

Find a DateTime closest to instant within a range. Read more

Auto Trait Implementations§

§

impl Freeze for Cron

§

impl RefUnwindSafe for Cron

§

impl Send for Cron

§

impl Sync for Cron

§

impl Unpin for Cron

§

impl UnwindSafe for Cron

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Combine for T
where T: Pattern,

Source§

fn and<P: Pattern>(self, other: P) -> Combined<Self, P>

Combine Self with another Pattern. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.