summaryrefslogtreecommitdiffstats
path: root/src/matcher.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-09-26 17:18:03 +0200
committerMatthias Beyer <mail@beyermatthias.de>2017-09-26 17:18:17 +0200
commit694a9a4ecb4f743ab7958a66a042381a812ad156 (patch)
tree17d970f6fc1ba0d66c1860bfd8473c1cabc21d85 /src/matcher.rs
parent8520fe52226d3586f9b4d7ece968f9bbf6450d0c (diff)
Add Matcher trait for indicators
Diffstat (limited to 'src/matcher.rs')
-rw-r--r--src/matcher.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/matcher.rs b/src/matcher.rs
new file mode 100644
index 0000000..1482b68
--- /dev/null
+++ b/src/matcher.rs
@@ -0,0 +1,37 @@
+
+use chrono::Datelike;
+
+use error::KairosError as KE;
+use error::KairosErrorKind as KEK;
+use error::Result;
+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<bool>;
+}
+
+impl Matcher for Day {
+
+ fn matches(&self, tt: &TimeType) -> Result<bool> {
+ let this : ::chrono::Weekday = self.clone().into();
+ tt.get_moment()
+ .map(|mom| this == mom.weekday())
+ .ok_or(KE::from_kind(KEK::ArgumentErrorNotAMoment(tt.name())))
+ }
+}
+
+impl Matcher for Month {
+
+ fn matches(&self, tt: &TimeType) -> Result<bool> {
+ let this : u32 = self.clone().into();
+ tt.get_moment()
+ .map(|mom| this == mom.month())
+ .ok_or(KE::from_kind(KEK::ArgumentErrorNotAMoment(tt.name())))
+ }
+
+}
+
+