Trait filters::filter::Filter
[−]
[src]
pub trait Filter<N> { fn filter(&self, _: &N) -> bool; fn not(self) -> Not<Self>
where
Self: Sized, { ... } fn or<F>(self, other: F) -> Or<Self, F::IntoFilt>
where
Self: Sized,
F: IntoFilter<N> + Sized, { ... } fn or_not<F>(self, other: F) -> Or<Self, Not<F::IntoFilt>>
where
Self: Sized,
F: IntoFilter<N> + Sized, { ... } fn or3<F, F2>(
self,
other: F,
other2: F2
) -> Or<Self, Or<F::IntoFilt, F2::IntoFilt>>
where
Self: Sized,
F: IntoFilter<N> + Sized,
F2: IntoFilter<N> + Sized, { ... } fn nor<F>(self, other: F) -> Not<Or<Self, F>>
where
Self: Sized, { ... } fn xor<F>(self, other: F) -> XOr<Self, F>
where
Self: Sized, { ... } fn and<F>(self, other: F) -> And<Self, F::IntoFilt>
where
Self: Sized,
F: IntoFilter<N> + Sized, { ... } fn and3<F, F2>(
self,
other: F,
other2: F2
) -> And<Self, And<F::IntoFilt, F2::IntoFilt>>
where
Self: Sized,
F: IntoFilter<N> + Sized,
F2: IntoFilter<N> + Sized, { ... } fn and_not<F>(self, other: F) -> And<Self, Not<F::IntoFilt>>
where
Self: Sized,
F: IntoFilter<N> + Sized, { ... } fn nand<F>(self, other: F) -> Not<And<Self, F>>
where
Self: Sized, { ... } fn map_input<O, B, T, M>(self, map: M) -> MapInput<Self, M, O, B>
where
Self: Sized,
M: Fn(&T) -> N,
B: Borrow<O> + Sized, { ... } fn into_failable(self) -> IntoFailable<Self, ()>
where
Self: Sized, { ... } fn as_failable<'a>(&'a self) -> AsFailable<'a, Self, ()>
where
Self: 'a, { ... } }
The filter trait
Required Methods
Provided Methods
fn not(self) -> Not<Self> where
Self: Sized,
Self: Sized,
Helper to invert a filter.
use filters::filter::Filter; let f = (|&a: &usize| { a == 1 }).not(); assert!(f.filter(&2));
fn or<F>(self, other: F) -> Or<Self, F::IntoFilt> where
Self: Sized,
F: IntoFilter<N> + Sized,
Self: Sized,
F: IntoFilter<N> + Sized,
Helper to connect two filters via logical OR
use filters::filter::Filter; let a = (|&a: &usize| { a == 1 }); let b = (|&a: &usize| { a == 2 }); let c = a.or(b); assert!(c.filter(&1)); assert!(c.filter(&2)); assert!(!c.filter(&7));
fn or_not<F>(self, other: F) -> Or<Self, Not<F::IntoFilt>> where
Self: Sized,
F: IntoFilter<N> + Sized,
Self: Sized,
F: IntoFilter<N> + Sized,
Helper to connect two filters via logical OR and NOT
use filters::filter::Filter; let a = (|&a: &usize| { a == 1 }); let b = (|&a: &usize| { a == 2 }); let c = a.or_not(b); assert!(c.filter(&1)); assert!(!c.filter(&2)); assert!(c.filter(&7));
fn or3<F, F2>(
self,
other: F,
other2: F2
) -> Or<Self, Or<F::IntoFilt, F2::IntoFilt>> where
Self: Sized,
F: IntoFilter<N> + Sized,
F2: IntoFilter<N> + Sized,
self,
other: F,
other2: F2
) -> Or<Self, Or<F::IntoFilt, F2::IntoFilt>> where
Self: Sized,
F: IntoFilter<N> + Sized,
F2: IntoFilter<N> + Sized,
Helper to connect three filters via logical OR
use filters::filter::Filter; let a = (|&a: &usize| { a == 1 }); let b = (|&a: &usize| { a == 2 }); let c = (|&a: &usize| { a == 3 }); let d = a.or3(b, c); assert!(d.filter(&1)); assert!(d.filter(&2)); assert!(d.filter(&3)); assert!(!d.filter(&4));
fn nor<F>(self, other: F) -> Not<Or<Self, F>> where
Self: Sized,
Self: Sized,
Helper to connect two filters via logical NOR
use filters::filter::Filter; let a = (|&a: &usize| { a == 1 }); let b = (|&a: &usize| { a == 2 }); let c = a.nor(b); /* !(a == 1 || a == 2) */ assert!(!c.filter(&1)); assert!(!c.filter(&2)); assert!(c.filter(&3)); assert!(c.filter(&4));
fn xor<F>(self, other: F) -> XOr<Self, F> where
Self: Sized,
Self: Sized,
Helper to connect two filters via logical XOR
use filters::filter::Filter; let a = (|&a: &usize| { a > 3 }); let b = (|&a: &usize| { a < 7 }); let c = a.xor(b); assert!(c.filter(&1)); assert!(c.filter(&3)); assert!(!c.filter(&4)); assert!(!c.filter(&6)); assert!(c.filter(&9));
fn and<F>(self, other: F) -> And<Self, F::IntoFilt> where
Self: Sized,
F: IntoFilter<N> + Sized,
Self: Sized,
F: IntoFilter<N> + Sized,
Helper to connect two filters via logical AND
use filters::filter::Filter; let a = (|&a: &usize| { a > 1 }); let b = (|&a: &usize| { a < 7 }); let c = a.and(b); assert!(!c.filter(&1)); assert!(c.filter(&3)); assert!(c.filter(&4)); assert!(c.filter(&6)); assert!(!c.filter(&9));
fn and3<F, F2>(
self,
other: F,
other2: F2
) -> And<Self, And<F::IntoFilt, F2::IntoFilt>> where
Self: Sized,
F: IntoFilter<N> + Sized,
F2: IntoFilter<N> + Sized,
self,
other: F,
other2: F2
) -> And<Self, And<F::IntoFilt, F2::IntoFilt>> where
Self: Sized,
F: IntoFilter<N> + Sized,
F2: IntoFilter<N> + Sized,
Helper to connect three filters via logical AND
use filters::filter::Filter; let a = (|&a: &usize| { a > 1 }); let b = (|&a: &usize| { a < 20 }); let c = (|&a: &usize| { a % 2 == 0 }); let d = a.and3(b, c); assert!(!d.filter(&1)); assert!(!d.filter(&3)); assert!(d.filter(&8)); assert!(d.filter(&10)); assert!(d.filter(&14)); assert!(!d.filter(&15)); assert!(!d.filter(&19));
fn and_not<F>(self, other: F) -> And<Self, Not<F::IntoFilt>> where
Self: Sized,
F: IntoFilter<N> + Sized,
Self: Sized,
F: IntoFilter<N> + Sized,
Helper to connect two filters via logical AND and NOT
use filters::filter::Filter; let a = (|&a: &usize| { a > 10 }); let b = (|&a: &usize| { a < 20 }); let c = a.and_not(b); assert!(!c.filter(&1)); assert!(!c.filter(&3)); assert!(!c.filter(&8)); assert!(!c.filter(&11)); assert!(c.filter(&24)); assert!(c.filter(&25)); assert!(c.filter(&29));
fn nand<F>(self, other: F) -> Not<And<Self, F>> where
Self: Sized,
Self: Sized,
Helper to connect two filters via logical NAND
use filters::filter::Filter; let a = (|&a: &usize| { a > 10 }); let b = (|&a: &usize| { a < 20 }); let c = a.nand(b); assert!(c.filter(&1)); assert!(c.filter(&3)); assert!(c.filter(&8)); assert!(!c.filter(&11)); assert!(!c.filter(&14)); assert!(c.filter(&25)); assert!(c.filter(&29));
fn map_input<O, B, T, M>(self, map: M) -> MapInput<Self, M, O, B> where
Self: Sized,
M: Fn(&T) -> N,
B: Borrow<O> + Sized,
Self: Sized,
M: Fn(&T) -> N,
B: Borrow<O> + Sized,
Helper to transform the input of a filter
use filters::filter::Filter; let a = (|&a: &usize| { a > 1 }); let b = (|&a: &i64| { a < 7 }); let b = b.map_input(|&x: &usize| { x as i64 }); let c = a.and(b); assert!(!c.filter(&1)); assert!(c.filter(&3)); assert!(c.filter(&4)); assert!(c.filter(&6)); assert!(!c.filter(&9));
fn into_failable(self) -> IntoFailable<Self, ()> where
Self: Sized,
Self: Sized,
Helper to transform a filter into a FailableFilter
use filters::filter::Filter; use filters::failable::filter::FailableFilter; let a = (|&a: &usize| { a > 5 }); let a = a.into_failable(); assert_eq!(a.filter(&3), Ok(false)); assert_eq!(a.filter(&5), Ok(false)); assert_eq!(a.filter(&7), Ok(true)); assert_eq!(a.filter(&9), Ok(true));
fn as_failable<'a>(&'a self) -> AsFailable<'a, Self, ()> where
Self: 'a,
Self: 'a,
Helper to borrow a filter as a FailbleFilter
use filters::filter::Filter; use filters::failable::filter::FailableFilter; let a = (|&a: &usize| { a > 5 }); let b = a.as_failable(); assert_eq!(a.filter(&3), false); assert_eq!(b.filter(&3), Ok(false)); assert_eq!(a.filter(&7), true); assert_eq!(b.filter(&7), Ok(true));
Implementors
impl<I, T: Fn(&I) -> bool> Filter<I> for T
impl<I, T: Filter<I>, U: Filter<I>> Filter<I> for And<T, U>
impl<I> Filter<I> for Bool
impl<I, T: Filter<I>> Filter<I> for Not<T>
impl<I, T: Filter<I>, U: Filter<I>> Filter<I> for Or<T, U>
impl<I, T: Filter<I>, U: Filter<I>> Filter<I> for XOr<T, U>
impl<FT, F, T, B, M> Filter<T> for MapInput<F, M, FT, B> where
F: Filter<FT>,
B: Borrow<FT> + Sized,
M: Fn(&T) -> B,