Macro filters::impl_operators [] [src]

macro_rules! impl_operators {
    ($struct_ident:ident, $self_var: ident $arg_var: ident $filter_impl:block, $( $generic:ident ),*) => { ... };
    ($struct_ident:ident, $self_var: ident $arg_var: ident $filter_impl: block) => { ... };
}

Creates operator implementations for a Filter struct Currently only Fn and Filter implementations are handled

Takes at least two arguments: the struct to implement the traits for, and the block to define the filter function. Preceeding the block should be the variables for self and the passed in argument to filter, separated by spaces. After that, any filter generics needed for the struct should be specified.

Examples

struct Or<T, U> {
    a: T,
    b: U
}

impl_operators!(Or, self e { self.a.filter(e) || self.b.filter(e) }, T, U);

let or = Or {a: |&x: &i32| x < 5, b: |&x: &i32| x > 10};
assert_eq!(or.filter(&0), true);
assert_eq!(or.filter(&7), false);
assert_eq!(or.filter(&15), true);
// If unstable-filter-as-fn is enabled `or` will also be a Fn(&i32) -> bool