summaryrefslogtreecommitdiffstats
path: root/libimagentryfilter
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-02-02 14:48:05 +0100
committerMatthias Beyer <mail@beyermatthias.de>2016-02-02 17:17:27 +0100
commit0fb331f25a5677c4d8aef3bc86b0c523f6d4b8c0 (patch)
treebd16b1545ce65873e708dd305bd7122af43cfbb3 /libimagentryfilter
parent10050db42f509c6f99e6fed95bb9aeca9ab77ef1 (diff)
Add Filter trait and operators
Diffstat (limited to 'libimagentryfilter')
-rw-r--r--libimagentryfilter/src/filter.rs30
-rw-r--r--libimagentryfilter/src/ops/and.rs24
-rw-r--r--libimagentryfilter/src/ops/not.rs23
-rw-r--r--libimagentryfilter/src/ops/or.rs24
4 files changed, 101 insertions, 0 deletions
diff --git a/libimagentryfilter/src/filter.rs b/libimagentryfilter/src/filter.rs
index e69de29b..8fa605b5 100644
--- a/libimagentryfilter/src/filter.rs
+++ b/libimagentryfilter/src/filter.rs
@@ -0,0 +1,30 @@
+use libimagstore::store::Entry;
+
+pub use ops::and::And;
+pub use ops::not::Not;
+pub use ops::or::Or;
+
+pub trait Filter {
+
+ fn filter(&self, &Entry) -> bool;
+
+ fn not(self) -> Not
+ where Self: Sized + 'static
+ {
+ Not::new(Box::new(self))
+ }
+
+ fn or(self, other: Box<Filter>) -> Or
+ where Self: Sized + 'static
+ {
+ Or::new(Box::new(self), other)
+ }
+
+ fn and(self, other: Box<Filter>) -> And
+ where Self: Sized + 'static
+ {
+ And::new(Box::new(self), other)
+ }
+
+}
+
diff --git a/libimagentryfilter/src/ops/and.rs b/libimagentryfilter/src/ops/and.rs
index e69de29b..79470b9b 100644
--- a/libimagentryfilter/src/ops/and.rs
+++ b/libimagentryfilter/src/ops/and.rs
@@ -0,0 +1,24 @@
+use libimagstore::store::Entry;
+
+use filter::Filter;
+
+pub struct And {
+ a: Box<Filter>,
+ b: Box<Filter>
+}
+
+impl And {
+
+ pub fn new(a: Box<Filter>, b: Box<Filter>) -> And {
+ And { a: a, b: b }
+ }
+
+}
+
+impl Filter for And {
+
+ fn filter(&self, e: &Entry) -> bool {
+ self.a.filter(e) && self.b.filter(e)
+ }
+
+}
diff --git a/libimagentryfilter/src/ops/not.rs b/libimagentryfilter/src/ops/not.rs
index e69de29b..a709d95b 100644
--- a/libimagentryfilter/src/ops/not.rs
+++ b/libimagentryfilter/src/ops/not.rs
@@ -0,0 +1,23 @@
+use libimagstore::store::Entry;
+
+use filter::Filter;
+
+pub struct Not {
+ a: Box<Filter>
+}
+
+impl Not {
+
+ pub fn new(a: Box<Filter>) -> Not {
+ Not { a: a }
+ }
+
+}
+
+impl Filter for Not {
+
+ fn filter(&self, e: &Entry) -> bool {
+ !self.a.filter(e)
+ }
+
+}
diff --git a/libimagentryfilter/src/ops/or.rs b/libimagentryfilter/src/ops/or.rs
index e69de29b..e2ca810b 100644
--- a/libimagentryfilter/src/ops/or.rs
+++ b/libimagentryfilter/src/ops/or.rs
@@ -0,0 +1,24 @@
+use libimagstore::store::Entry;
+
+use filter::Filter;
+
+pub struct Or {
+ a: Box<Filter>,
+ b: Box<Filter>
+}
+
+impl Or {
+
+ pub fn new(a: Box<Filter>, b: Box<Filter>) -> Or {
+ Or { a: a, b: b }
+ }
+
+}
+
+impl Filter for Or {
+
+ fn filter(&self, e: &Entry) -> bool {
+ self.a.filter(e) || self.b.filter(e)
+ }
+
+}