use chrono::Datelike; use error::ErrorKind as KEK; use failure::Fallible as Result; use failure::Error; use indicator::Day; use indicator::Month; use timetype::TimeType; /// A trait to extend indicator::* to be able to match them with a TimeType object pub trait Matcher { fn matches(&self, tt: &TimeType) -> Result; } impl Matcher for Day { fn matches(&self, tt: &TimeType) -> Result { let this : ::chrono::Weekday = self.clone().into(); tt.get_moment() .map(|mom| this == mom.weekday()) .ok_or(Error::from(KEK::ArgumentErrorNotAMoment(tt.name()))) } } impl Matcher for Month { fn matches(&self, tt: &TimeType) -> Result { let this : u32 = self.clone().into(); tt.get_moment() .map(|mom| this == mom.month()) .ok_or(Error::from(KEK::ArgumentErrorNotAMoment(tt.name()))) } } #[cfg(feature = "with-filters")] use filters::filter::*; #[cfg(feature = "with-filters")] impl Matcher for F where F: Filter { fn matches(&self, tt: &TimeType) -> Result { Ok(self.filter(tt)) } }