summaryrefslogtreecommitdiffstats
path: root/src/failable/ops/or.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/failable/ops/or.rs')
-rw-r--r--src/failable/ops/or.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/failable/ops/or.rs b/src/failable/ops/or.rs
new file mode 100644
index 0000000..45289c3
--- /dev/null
+++ b/src/failable/ops/or.rs
@@ -0,0 +1,35 @@
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+//
+
+//! OR implementation.
+//!
+//! Will be automatically included when including `filter::Filter`, so importing this module
+//! shouldn't be necessary.
+//!
+
+use failable::filter::FailableFilter;
+
+#[must_use = "filters are lazy and do nothing unless consumed"]
+#[derive(Clone)]
+pub struct FailableOr<T, U>(T, U);
+
+impl<T, U> FailableOr<T, U> {
+
+ pub fn new(a: T, b: U) -> FailableOr<T, U> {
+ FailableOr(a, b)
+ }
+
+}
+
+impl<N, E, T, U> FailableFilter<N, E> for FailableOr<T, U>
+ where T: FailableFilter<N, E>,
+ U: FailableFilter<N, E>
+{
+ fn filter(&self, e: &N) -> Result<bool, E> {
+ Ok(try!(self.0.filter(e)) || try!(self.1.filter(e)))
+ }
+}
+