diff options
Diffstat (limited to 'src/failable/ops/xor.rs')
-rw-r--r-- | src/failable/ops/xor.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/failable/ops/xor.rs b/src/failable/ops/xor.rs new file mode 100644 index 0000000..b0a100d --- /dev/null +++ b/src/failable/ops/xor.rs @@ -0,0 +1,38 @@ +// +// 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/. +// + +//! XOR 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 FailableXOr<T, U>(T, U); + +impl<T, U> FailableXOr<T, U> { + + pub fn new(a: T, b: U) -> FailableXOr<T, U> { + FailableXOr(a, b) + } + +} + +impl<N, E, T, U> FailableFilter<N, E> for FailableXOr<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))) + } +} + + |