summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-10-03 10:26:05 +0200
committerMatthias Beyer <mail@beyermatthias.de>2017-10-03 10:26:05 +0200
commite668b6818c61f8f9f51821d6cda79a160d1fce75 (patch)
tree12d2c298db1c1ae368334f629fb9355c29fe4abb
parentbdc2c062c2632fd6e0f9be4113b239f1cf84f0b9 (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.
-rw-r--r--src/failable/filter.rs141
-rw-r--r--src/failable/ops/and.rs4
-rw-r--r--src/failable/ops/bool.rs3
-rw-r--r--src/failable/ops/map.rs8
-rw-r--r--src/failable/ops/not.rs4
-rw-r--r--src/failable/ops/or.rs4
-rw-r--r--src/failable/ops/xor.rs4
7 files changed, 11 insertions, 157 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) };
diff --git a/src/failable/ops/and.rs b/src/failable/ops/and.rs
index 7cb883d..9c1d547 100644
--- a/src/failable/ops/and.rs
+++ b/src/failable/ops/and.rs
@@ -10,7 +10,6 @@
//! shouldn't be necessary.
//!
-use std::error::Error;
use failable::filter::FailableFilter;
#[must_use = "filters are lazy and do nothing unless consumed"]
@@ -26,8 +25,7 @@ impl<T, U> FailableAnd<T, U> {
}
impl<N, E, T, U> FailableFilter<N, E> for FailableAnd<T, U>
- where E: Error,
- T: FailableFilter<N, E>,
+ where T: FailableFilter<N, E>,
U: FailableFilter<N, E>
{
fn filter(&self, e: &N) -> Result<bool, E> {
diff --git a/src/failable/ops/bool.rs b/src/failable/ops/bool.rs
index aef1077..def51dd 100644
--- a/src/failable/ops/bool.rs
+++ b/src/failable/ops/bool.rs
@@ -10,7 +10,6 @@
//! shouldn't be necessary.
//!
-use std::error::Error;
use failable::filter::FailableFilter;
#[must_use = "filters are lazy and do nothing unless consumed"]
@@ -33,7 +32,7 @@ impl From<bool> for FailableBool {
}
-impl<N, E: Error> FailableFilter<N, E> for FailableBool {
+impl<N, E> FailableFilter<N, E> for FailableBool {
fn filter(&self, _: &N) -> Result<bool, E> {
Ok(self.0)
}
diff --git a/src/failable/ops/map.rs b/src/failable/ops/map.rs
index 8e1155c..1d51e6c 100644
--- a/src/failable/ops/map.rs
+++ b/src/failable/ops/map.rs
@@ -11,7 +11,6 @@
//!
use std::marker::PhantomData;
use std::borrow::Borrow;
-use std::error::Error;
use failable::filter::FailableFilter;
@@ -26,8 +25,7 @@ impl<F, M, FT, B> FailableMapInput<F, M, FT, B> {
}
impl<FT, E, F, T, B, M> FailableFilter<T, E> for FailableMapInput<F, M, FT, B>
- where E: Error,
- F: FailableFilter<FT, E>,
+ where F: FailableFilter<FT, E>,
B: Borrow<FT> + Sized,
M: Fn(&T) -> B
{
@@ -47,9 +45,7 @@ impl<F, M, FE, E> FailableMapErr<F, M, FE, E> {
}
impl<FE, E, F, T, M> FailableFilter<T, E> for FailableMapErr<F, M, FE, E>
- where E: Error,
- FE: Error,
- F: FailableFilter<T, FE>,
+ where F: FailableFilter<T, FE>,
M: Fn(FE) -> E
{
fn filter(&self, e: &T) -> Result<bool, E> {
diff --git a/src/failable/ops/not.rs b/src/failable/ops/not.rs
index 14c5a7e..3712024 100644
--- a/src/failable/ops/not.rs
+++ b/src/failable/ops/not.rs
@@ -10,7 +10,6 @@
//! shouldn't be necessary.
//!
-use std::error::Error;
use failable::filter::FailableFilter;
#[must_use = "filters are lazy and do nothing unless consumed"]
@@ -26,8 +25,7 @@ impl<T> FailableNot<T> {
}
impl<N, E, T> FailableFilter<N, E> for FailableNot<T>
- where E: Error,
- T: FailableFilter<N, E>
+ where T: FailableFilter<N, E>
{
fn filter(&self, e: &N) -> Result<bool, E> {
self.0.filter(e).map(|b| !b)
diff --git a/src/failable/ops/or.rs b/src/failable/ops/or.rs
index 2a35aee..311e5dd 100644
--- a/src/failable/ops/or.rs
+++ b/src/failable/ops/or.rs
@@ -10,7 +10,6 @@
//! shouldn't be necessary.
//!
-use std::error::Error;
use failable::filter::FailableFilter;
#[must_use = "filters are lazy and do nothing unless consumed"]
@@ -26,8 +25,7 @@ impl<T, U> FailableOr<T, U> {
}
impl<N, E, T, U> FailableFilter<N, E> for FailableOr<T, U>
- where E: Error,
- T: FailableFilter<N, E>,
+ where T: FailableFilter<N, E>,
U: FailableFilter<N, E>
{
fn filter(&self, e: &N) -> Result<bool, E> {
diff --git a/src/failable/ops/xor.rs b/src/failable/ops/xor.rs
index b0a100d..23c37c4 100644
--- a/src/failable/ops/xor.rs
+++ b/src/failable/ops/xor.rs
@@ -10,7 +10,6 @@
//! shouldn't be necessary.
//!
-use std::error::Error;
use failable::filter::FailableFilter;
#[must_use = "filters are lazy and do nothing unless consumed"]
@@ -26,8 +25,7 @@ impl<T, U> FailableXOr<T, U> {
}
impl<N, E, T, U> FailableFilter<N, E> for FailableXOr<T, U>
- where E: Error,
- T: FailableFilter<N, E>,
+ where T: FailableFilter<N, E>,
U: FailableFilter<N, E>
{
fn filter(&self, e: &N) -> Result<bool, E> {