diff --git a/src/lib.rs b/src/lib.rs index d2bce4d..9c38156 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -455,6 +455,16 @@ impl Cron { self.pattern.with_alternative_weekdays(); self } + + pub fn as_str(&self) -> &str { + self.pattern.as_str() + } +} + +impl std::fmt::Display for Cron { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.pattern) + } } // Enables creating a Cron instance from a string slice, returning a CronError if parsing fails. diff --git a/src/pattern.rs b/src/pattern.rs index 034eb4d..92b6807 100644 --- a/src/pattern.rs +++ b/src/pattern.rs @@ -506,11 +506,16 @@ impl CronPattern { self.days_of_week = CronComponent::new(0, 7, LAST_BIT | NTH_ALL, 1); self } + + // Get a reference to the original pattern + pub fn as_str(&self) -> &str { + &self.pattern + } } -impl ToString for CronPattern { - fn to_string(&self) -> String { - self.pattern.clone() +impl std::fmt::Display for CronPattern { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.pattern) } }