use filter::Filter;
use failable::filter::FailableFilter;
#[must_use = "filters are lazy and do nothing unless consumed"]
#[derive(Clone)]
pub struct IntoFailable<F>(F);
impl<F> IntoFailable<F> {
pub fn new(a: F) -> IntoFailable<F> {
IntoFailable(a)
}
}
impl<F, N> FailableFilter<N> for IntoFailable<F>
where F: Filter<N>,
{
type Error = ();
fn filter(&self, e: &N) -> Result<bool, Self::Error> {
Ok(self.0.filter(e))
}
}
#[must_use = "filters are lazy and do nothing unless consumed"]
#[derive(Clone)]
pub struct AsFailable<'a, F: 'a + ?Sized>(&'a F);
impl<'a, F: 'a + ?Sized> AsFailable<'a, F> {
pub fn new(a: &'a F) -> AsFailable<F> {
AsFailable(a)
}
}
impl<'a, F, N> FailableFilter<N> for AsFailable<'a, F>
where F: Filter<N> + 'a + ?Sized,
{
type Error = ();
fn filter(&self, e: &N) -> Result<bool, Self::Error> {
Ok(self.0.filter(e))
}
}