summaryrefslogtreecommitdiffstats
path: root/src/failable/ops/and.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-10-01 11:24:01 +0200
committerMatthias Beyer <mail@beyermatthias.de>2017-10-01 13:55:16 +0200
commitebd9d4e90c252ff8f20c3f1733b4884e08a66c78 (patch)
treea50476ed645006872aafa449cffe5fbee891371e /src/failable/ops/and.rs
parent3d99f7879186c6be4c4b1ef86d02113bf6685e8b (diff)
Add failable filter infrastructure
Diffstat (limited to 'src/failable/ops/and.rs')
-rw-r--r--src/failable/ops/and.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/failable/ops/and.rs b/src/failable/ops/and.rs
new file mode 100644
index 0000000..7cb883d
--- /dev/null
+++ b/src/failable/ops/and.rs
@@ -0,0 +1,37 @@
+//
+// 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/.
+//
+
+//! AND implementation.
+//!
+//! Will be automatically included when incluing `filter::Filter`, so importing this module
+//! shouldn't be necessary.
+//!
+
+use std::error::Error;
+use failable::filter::FailableFilter;
+
+#[must_use = "filters are lazy and do nothing unless consumed"]
+#[derive(Clone)]
+pub struct FailableAnd<T, U>(T, U);
+
+impl<T, U> FailableAnd<T, U> {
+
+ pub fn new(a: T, b: U) -> FailableAnd<T, U> {
+ FailableAnd(a, b)
+ }
+
+}
+
+impl<N, E, T, U> FailableFilter<N, E> for FailableAnd<T, U>
+ where E: Error,
+ 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)))
+ }
+}
+