diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2017-09-26 17:41:20 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2017-09-26 17:57:56 +0200 |
commit | 4be0e3b361615a84ecf1402b827a81ca62e95bc5 (patch) | |
tree | 900ca070850269155815499b88307566cecd0a50 /src/indicator.rs | |
parent | 77c3f75343dc84b87e99e333bc15ea5c308fc017 (diff) |
Implement filter interface for matchers
Diffstat (limited to 'src/indicator.rs')
-rw-r--r-- | src/indicator.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/indicator.rs b/src/indicator.rs index 7a57b7e..72e1136 100644 --- a/src/indicator.rs +++ b/src/indicator.rs @@ -57,3 +57,45 @@ impl Into<u32> for Month { } } } + +#[cfg(feature = "with-filters")] +pub struct DayFilter(Day); + +#[cfg(feature = "with-filters")] +impl Filter<TimeType> for DayFilter { + fn filter(&self, tt: &TimeType) -> bool { + tt.get_moment(|mom| mom.weekday() == self.0.into()).unwrap_or(false) + } +} + +#[cfg(feature = "with-filters")] +impl IntoFilter<TimeType> for Day { + type IntoFilt = DayFilter; + + fn into_filter(self) -> Self::IntoFilt { + DayFilter(self) + } + +} + + +#[cfg(feature = "with-filters")] +pub struct MonthFilter(Month); + +#[cfg(feature = "with-filters")] +impl Filter<TimeType> for MonthFilter { + fn filter(&self, tt: &TimeType) -> bool { + tt.get_moment(|mom| mom.month() == self.0.into()).unwrap_or(false) + } +} + +#[cfg(feature = "with-filters")] +impl IntoFilter<TimeType> for Month { + type IntoFilt = MonthFilter; + + fn into_filter(self) -> Self::IntoFilt { + MonthFilter(self) + } + +} + |