summaryrefslogtreecommitdiffstats
path: root/src/ops
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-08-12 12:45:46 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-08-12 12:47:58 +0200
commit99a6e7820b22c8eb49d957a4c9e947d6185ac4fd (patch)
treedc53a17a932a19ed7a9061a5f768bc7a8e134b10 /src/ops
parent90673d79c10e70bbcabf7c54c28e171c32883ba1 (diff)
Add XOr type and Filter::xor()
Diffstat (limited to 'src/ops')
-rw-r--r--src/ops/mod.rs1
-rw-r--r--src/ops/xor.rs32
2 files changed, 33 insertions, 0 deletions
diff --git a/src/ops/mod.rs b/src/ops/mod.rs
index 668eedc..e5881af 100644
--- a/src/ops/mod.rs
+++ b/src/ops/mod.rs
@@ -1,3 +1,4 @@
pub mod and;
pub mod not;
pub mod or;
+pub mod xor;
diff --git a/src/ops/xor.rs b/src/ops/xor.rs
new file mode 100644
index 0000000..42591d4
--- /dev/null
+++ b/src/ops/xor.rs
@@ -0,0 +1,32 @@
+//! XOR implementation.
+//!
+//! Will be automatically included when incluing `filter::Filter`, so importing this module
+//! shouldn't be necessary.
+//!
+use filter::Filter;
+
+#[must_use = "filters are lazy and do nothing unless consumed"]
+#[derive(Clone)]
+pub struct XOr<T, U> {
+ a: T,
+ b: U
+}
+
+impl<T, U> XOr<T, U> {
+
+ pub fn new(a: T, b: U) -> XOr<T, U> {
+ XOr { a: a, b: b }
+ }
+
+}
+
+impl<I, T: Filter<I>, U: Filter<I>> Filter<I> for XOr<T, U> {
+
+ fn filter(&self, e: &I) -> bool {
+ let a = self.a.filter(e);
+ let b = self.b.filter(e);
+
+ (a && !b) || (!a && b)
+ }
+
+}