diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-08-10 09:53:43 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-08-10 09:53:43 +0200 |
commit | b79d8963fc79da66b9efc55fd5fa45bb0b98c051 (patch) | |
tree | 65cd46d785db344306786cfeaa8cd561011cc16a /src | |
parent | 200ce879d8dd6dc19fc60f72d2c8929f26f91c3c (diff) |
Add ops
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 1 | ||||
-rw-r--r-- | src/ops/and.rs | 22 | ||||
-rw-r--r-- | src/ops/mod.rs | 3 | ||||
-rw-r--r-- | src/ops/not.rs | 21 | ||||
-rw-r--r-- | src/ops/or.rs | 22 |
5 files changed, 69 insertions, 0 deletions
@@ -1 +1,2 @@ pub mod filter; +pub mod ops; diff --git a/src/ops/and.rs b/src/ops/and.rs new file mode 100644 index 0000000..8d79b42 --- /dev/null +++ b/src/ops/and.rs @@ -0,0 +1,22 @@ +use filter::Filter; + +pub struct And<T> { + a: Box<Filter<T>>, + b: Box<Filter<T>> +} + +impl<T> And<T> { + + pub fn new(a: Box<Filter<T>>, b: Box<Filter<T>>) -> And<T> { + And { a: a, b: b } + } + +} + +impl<T> Filter<T> for And<T> { + + fn filter(&self, e: &T) -> bool { + self.a.filter(e) && self.b.filter(e) + } + +} diff --git a/src/ops/mod.rs b/src/ops/mod.rs new file mode 100644 index 0000000..668eedc --- /dev/null +++ b/src/ops/mod.rs @@ -0,0 +1,3 @@ +pub mod and; +pub mod not; +pub mod or; diff --git a/src/ops/not.rs b/src/ops/not.rs new file mode 100644 index 0000000..a7c5c76 --- /dev/null +++ b/src/ops/not.rs @@ -0,0 +1,21 @@ +use filter::Filter; + +pub struct Not<T> { + a: Box<Filter<T>> +} + +impl<T> Not<T> { + + pub fn new(a: Box<Filter<T>>) -> Not<T> { + Not { a: a } + } + +} + +impl<T> Filter<T> for Not<T> { + + fn filter(&self, e: &T) -> bool { + !self.a.filter(e) + } + +} diff --git a/src/ops/or.rs b/src/ops/or.rs new file mode 100644 index 0000000..b001d75 --- /dev/null +++ b/src/ops/or.rs @@ -0,0 +1,22 @@ +use filter::Filter; + +pub struct Or<T> { + a: Box<Filter<T>>, + b: Box<Filter<T>> +} + +impl<T> Or<T> { + + pub fn new(a: Box<Filter<T>>, b: Box<Filter<T>>) -> Or<T> { + Or { a: a, b: b } + } + +} + +impl<T> Filter<T> for Or<T> { + + fn filter(&self, e: &T) -> bool { + self.a.filter(e) || self.b.filter(e) + } + +} |