File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -2,10 +2,31 @@ use std::any::Any;
22
33use crate :: Mutator ;
44
5+ /// A [`FilterMutator`] provides a way to filter values outputted by a mutator.
6+ /// Given any [`Mutator<Value=T>`] and a function [`Fn(&T) -> bool`] it creates
7+ /// a new mutator which can generate all the values of `T` the underlying
8+ /// mutator can, except those for which the filtering function returns false.
59pub struct FilterMutator < M , F > {
6- pub mutator : M ,
7- pub filter : F ,
10+ mutator : M ,
11+ filter : F ,
812}
13+
14+ impl < M , F > FilterMutator < M , F > {
15+ /// Creates a new [`FilterMutator`].
16+ ///
17+ /// Note that the mutator will filter all values for which the filtering
18+ /// function returns _false_.
19+ pub fn new < T > ( mutator : M , filter : F ) -> FilterMutator < M , F >
20+ where
21+ M : Mutator < T > ,
22+ T : Clone + ' static ,
23+ F : Fn ( & T ) -> bool ,
24+ Self : ' static ,
25+ {
26+ FilterMutator { mutator, filter }
27+ }
28+ }
29+
930impl < T , M , F > Mutator < T > for FilterMutator < M , F >
1031where
1132 M : Mutator < T > ,
Original file line number Diff line number Diff line change @@ -140,9 +140,9 @@ where
140140 #[ no_coverage]
141141 fn filter < F > ( self , filter : F ) -> FilterMutator < Self , F >
142142 where
143- F : Fn ( & T ) -> bool ,
143+ F : Fn ( & T ) -> bool + ' static ,
144144 {
145- FilterMutator { mutator : self , filter }
145+ FilterMutator :: new ( self , filter)
146146 }
147147 /// Create a mutator which wraps `self` and transforms the values generated by `self`
148148 /// using the `map` closure. The second closure, `parse`, should apply the opposite
You can’t perform that action at this time.
0 commit comments