use std::fmt::Display;
pub trait IntoCronValue {
fn into_cron_value(self) -> String;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum DayOfWeek {
Sunday = 0,
Monday = 1,
Tuesday = 2,
Wednesday = 3,
Thursday = 4,
Friday = 5,
Saturday = 6,
}
impl IntoCronValue for DayOfWeek {
fn into_cron_value(self) -> String {
(self as u32).to_string()
}
}
impl IntoCronValue for u32 {
fn into_cron_value(self) -> String {
self.to_string()
}
}
impl IntoCronValue for i32 {
fn into_cron_value(self) -> String {
self.to_string()
}
}
impl IntoCronValue for &str {
fn into_cron_value(self) -> String {
self.to_string()
}
}
impl IntoCronValue for String {
fn into_cron_value(self) -> String {
self
}
}
impl<T: Display> IntoCronValue for &[T] {
fn into_cron_value(self) -> String {
self.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
.join(",")
}
}
impl<T: Display, const N: usize> IntoCronValue for [T; N] {
fn into_cron_value(self) -> String {
self.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
.join(",")
}
}
impl<T: Display, const N: usize> IntoCronValue for &[T; N] {
fn into_cron_value(self) -> String {
self.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
.join(",")
}
}