diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2017-10-03 10:26:05 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2017-10-03 10:26:05 +0200 |
commit | e668b6818c61f8f9f51821d6cda79a160d1fce75 (patch) | |
tree | 12d2c298db1c1ae368334f629fb9355c29fe4abb /src/failable/filter.rs | |
parent | bdc2c062c2632fd6e0f9be4113b239f1cf84f0b9 (diff) |
Lessen restriction for Result second type param
Before we had the restriction that the Err(_) part of the Result must be
an Error, but as Result itself does not have such a bound, we remove
ours as well.
Diffstat (limited to 'src/failable/filter.rs')
-rw-r--r-- | src/failable/filter.rs | 141 |
1 files changed, 4 insertions, 137 deletions
diff --git a/src/failable/filter.rs b/src/failable/filter.rs index af08fbb..a872543 100644 --- a/src/failable/filter.rs +++ b/src/failable/filter.rs @@ -4,7 +4,6 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. // -use std::error::Error; use std::borrow::Borrow; pub use failable::ops::and::FailableAnd; @@ -15,14 +14,14 @@ pub use failable::ops::or::FailableOr; pub use failable::ops::map::{FailableMapInput, FailableMapErr}; /// Trait for converting something into a Filter -pub trait IntoFailableFilter<N, E: Error + Sized> { +pub trait IntoFailableFilter<N, E: Sized> { type IntoFilt: FailableFilter<N, E>; fn into_failable_filter(self) -> Self::IntoFilt; } /// All Filters can be turned into Filters -impl<N, E: Error + Sized, I: FailableFilter<N, E>> IntoFailableFilter<N, E> for I { +impl<N, E: Sized, I: FailableFilter<N, E>> IntoFailableFilter<N, E> for I { type IntoFilt = I; fn into_failable_filter(self) -> Self::IntoFilt { @@ -30,7 +29,7 @@ impl<N, E: Error + Sized, I: FailableFilter<N, E>> IntoFailableFilter<N, E> for } } -pub trait FailableFilter<N, E: Error> { +pub trait FailableFilter<N, E> { /// The function which is used to filter something fn filter(&self, &N) -> Result<bool, E>; @@ -40,16 +39,6 @@ pub trait FailableFilter<N, E: Error> { /// # #[derive(Debug)] /// # struct ErrorStub { } /// # - /// # impl ::std::fmt::Display for ErrorStub { - /// # fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { - /// # Ok(()) - /// # } - /// # } - /// # - /// # impl ::std::error::Error for ErrorStub { - /// # fn description(&self) -> &str { "stub" } - /// # } - /// # /// use filters::failable::filter::FailableFilter; /// /// let f = (|&a: &usize| -> Result<bool, ErrorStub> { Ok(a == 1) }).not(); @@ -68,16 +57,6 @@ pub trait FailableFilter<N, E: Error> { /// # #[derive(Debug)] /// # struct ErrorStub { } /// # - /// # impl ::std::fmt::Display for ErrorStub { - /// # fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { - /// # Ok(()) - /// # } - /// # } - /// # - /// # impl ::std::error::Error for ErrorStub { - /// # fn description(&self) -> &str { "stub" } - /// # } - /// # /// use filters::failable::filter::FailableFilter; /// /// let a = (|&a: &usize| -> Result<bool, ErrorStub> { Ok(a == 1) }); @@ -101,16 +80,6 @@ pub trait FailableFilter<N, E: Error> { /// # #[derive(Debug)] /// # struct ErrorStub { } /// # - /// # impl ::std::fmt::Display for ErrorStub { - /// # fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { - /// # Ok(()) - /// # } - /// # } - /// # - /// # impl ::std::error::Error for ErrorStub { - /// # fn description(&self) -> &str { "stub" } - /// # } - /// # /// use filters::failable::filter::FailableFilter; /// /// let a = (|&a: &usize| -> Result<bool, ErrorStub> { Ok(a == 1) }); @@ -134,16 +103,6 @@ pub trait FailableFilter<N, E: Error> { /// # #[derive(Debug)] /// # struct ErrorStub { } /// # - /// # impl ::std::fmt::Display for ErrorStub { - /// # fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { - /// # Ok(()) - /// # } - /// # } - /// # - /// # impl ::std::error::Error for ErrorStub { - /// # fn description(&self) -> &str { "stub" } - /// # } - /// # /// use filters::failable::filter::FailableFilter; /// /// let a = (|&a: &usize| -> Result<bool, ErrorStub> { Ok(a == 1) }); @@ -170,16 +129,6 @@ pub trait FailableFilter<N, E: Error> { /// # #[derive(Debug)] /// # struct ErrorStub { } /// # - /// # impl ::std::fmt::Display for ErrorStub { - /// # fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { - /// # Ok(()) - /// # } - /// # } - /// # - /// # impl ::std::error::Error for ErrorStub { - /// # fn description(&self) -> &str { "stub" } - /// # } - /// # /// use filters::failable::filter::FailableFilter; /// /// let a = (|&a: &usize| -> Result<bool, ErrorStub> { Ok(a == 1) }); @@ -203,16 +152,6 @@ pub trait FailableFilter<N, E: Error> { /// # #[derive(Debug)] /// # struct ErrorStub { } /// # - /// # impl ::std::fmt::Display for ErrorStub { - /// # fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { - /// # Ok(()) - /// # } - /// # } - /// # - /// # impl ::std::error::Error for ErrorStub { - /// # fn description(&self) -> &str { "stub" } - /// # } - /// # /// use filters::failable::filter::FailableFilter; /// /// let a = (|&a: &usize| -> Result<bool, ErrorStub> { Ok(a > 3) }); @@ -237,16 +176,6 @@ pub trait FailableFilter<N, E: Error> { /// # #[derive(Debug)] /// # struct ErrorStub { } /// # - /// # impl ::std::fmt::Display for ErrorStub { - /// # fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { - /// # Ok(()) - /// # } - /// # } - /// # - /// # impl ::std::error::Error for ErrorStub { - /// # fn description(&self) -> &str { "stub" } - /// # } - /// # /// use filters::failable::filter::FailableFilter; /// /// let a = (|&a: &usize| -> Result<bool, ErrorStub> { Ok(a > 1) }); @@ -272,16 +201,6 @@ pub trait FailableFilter<N, E: Error> { /// # #[derive(Debug)] /// # struct ErrorStub { } /// # - /// # impl ::std::fmt::Display for ErrorStub { - /// # fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { - /// # Ok(()) - /// # } - /// # } - /// # - /// # impl ::std::error::Error for ErrorStub { - /// # fn description(&self) -> &str { "stub" } - /// # } - /// # /// use filters::failable::filter::FailableFilter; /// /// let a = (|&a: &usize| -> Result<bool, ErrorStub> { Ok(a > 1) }); @@ -311,16 +230,6 @@ pub trait FailableFilter<N, E: Error> { /// # #[derive(Debug)] /// # struct ErrorStub { } /// # - /// # impl ::std::fmt::Display for ErrorStub { - /// # fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { - /// # Ok(()) - /// # } - /// # } - /// # - /// # impl ::std::error::Error for ErrorStub { - /// # fn description(&self) -> &str { "stub" } - /// # } - /// # /// use filters::failable::filter::FailableFilter; /// /// let a = (|&a: &usize| -> Result<bool, ErrorStub> { Ok(a > 10) }); @@ -348,16 +257,6 @@ pub trait FailableFilter<N, E: Error> { /// # #[derive(Debug)] /// # struct ErrorStub { } /// # - /// # impl ::std::fmt::Display for ErrorStub { - /// # fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { - /// # Ok(()) - /// # } - /// # } - /// # - /// # impl ::std::error::Error for ErrorStub { - /// # fn description(&self) -> &str { "stub" } - /// # } - /// # /// use filters::failable::filter::FailableFilter; /// /// let a = (|&a: &usize| -> Result<bool, ErrorStub> { Ok(a > 10) }); @@ -384,16 +283,6 @@ pub trait FailableFilter<N, E: Error> { /// # #[derive(Debug)] /// # struct ErrorStub { } /// # - /// # impl ::std::fmt::Display for ErrorStub { - /// # fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { - /// # Ok(()) - /// # } - /// # } - /// # - /// # impl ::std::error::Error for ErrorStub { - /// # fn description(&self) -> &str { "stub" } - /// # } - /// # /// use filters::failable::filter::FailableFilter; /// /// let a = (|&a: &usize| -> Result<bool, ErrorStub> { Ok(a > 1) }); @@ -422,16 +311,6 @@ pub trait FailableFilter<N, E: Error> { /// # #[derive(Debug)] /// # struct ErrorStub { } /// # - /// # impl ::std::fmt::Display for ErrorStub { - /// # fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { - /// # Ok(()) - /// # } - /// # } - /// # - /// # impl ::std::error::Error for ErrorStub { - /// # fn description(&self) -> &str { "stub" } - /// # } - /// # /// use filters::failable::filter::FailableFilter; /// /// let a = (|&a: &usize| -> Result<bool, ErrorStub> { Ok(a > 1) }); @@ -455,7 +334,7 @@ pub trait FailableFilter<N, E: Error> { } /// All closures that take a ref to something and return Result<bool, E> are failable filters -impl<I, E: Error, T: Fn(&I) -> Result<bool, E>> FailableFilter<I, E> for T { +impl<I, E, T: Fn(&I) -> Result<bool, E>> FailableFilter<I, E> for T { fn filter(&self, other: &I) -> Result<bool, E>{ self(other) } @@ -468,18 +347,6 @@ mod tests { #[derive(Debug)] struct StupError { } - impl ::std::fmt::Display for StupError { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { - Ok(()) - } - } - - impl Error for StupError { - fn description(&self) -> &str { - "stub" - } - } - #[test] fn compile_test() { let a = |r: &i32| -> Result<bool, StupError> { Ok(true) }; |