Skip to content

Commit

Permalink
impl Display for Cron and as_str to get the original pattern (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
veeshi authored Nov 23, 2024
1 parent 1b11486 commit cc5a0ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 8 additions & 3 deletions src/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit cc5a0ee

Please sign in to comment.