6
6
// option. This file may not be copied, modified, or distributed
7
7
// except according to those terms.
8
8
9
- use boolean:: { AndPredicate , NotPredicate , OrPredicate } ;
10
- use boxed:: BoxPredicate ;
11
-
12
9
/// Trait for generically evaluating a type against a dynamically created
13
10
/// predicate function.
14
11
///
@@ -20,93 +17,4 @@ pub trait Predicate<Item: ?Sized> {
20
17
/// Execute this `Predicate` against `variable`, returning the resulting
21
18
/// boolean.
22
19
fn eval ( & self , variable : & Item ) -> bool ;
23
-
24
- /// Compute the logical AND of two `Predicate` results, returning the result.
25
- ///
26
- /// # Examples
27
- ///
28
- /// ```
29
- /// use predicates::prelude::*;
30
- ///
31
- /// let predicate_fn1 = predicate::always().and(predicate::always());
32
- /// let predicate_fn2 = predicate::always().and(predicate::never());
33
- /// assert_eq!(true, predicate_fn1.eval(&4));
34
- /// assert_eq!(false, predicate_fn2.eval(&4));
35
- fn and < B > ( self , other : B ) -> AndPredicate < Self , B , Item >
36
- where
37
- B : Predicate < Item > ,
38
- Self : Sized ,
39
- {
40
- AndPredicate :: new ( self , other)
41
- }
42
-
43
- /// Compute the logical OR of two `Predicate` results, returning the result.
44
- ///
45
- /// # Examples
46
- ///
47
- /// ```
48
- /// use predicates::prelude::*;
49
- ///
50
- /// let predicate_fn1 = predicate::always().or(predicate::always());
51
- /// let predicate_fn2 = predicate::always().or(predicate::never());
52
- /// let predicate_fn3 = predicate::never().or(predicate::never());
53
- /// assert_eq!(true, predicate_fn1.eval(&4));
54
- /// assert_eq!(true, predicate_fn2.eval(&4));
55
- /// assert_eq!(false, predicate_fn3.eval(&4));
56
- fn or < B > ( self , other : B ) -> OrPredicate < Self , B , Item >
57
- where
58
- B : Predicate < Item > ,
59
- Self : Sized ,
60
- {
61
- OrPredicate :: new ( self , other)
62
- }
63
-
64
- /// Compute the logical NOT of a `Predicate`, returning the result.
65
- ///
66
- /// # Examples
67
- ///
68
- /// ```
69
- /// use predicates::prelude::*;
70
- ///
71
- /// let predicate_fn1 = predicate::always().not();
72
- /// let predicate_fn2 = predicate::never().not();
73
- /// assert_eq!(false, predicate_fn1.eval(&4));
74
- /// assert_eq!(true, predicate_fn2.eval(&4));
75
- fn not ( self ) -> NotPredicate < Self , Item >
76
- where
77
- Self : Sized ,
78
- {
79
- NotPredicate :: new ( self )
80
- }
81
-
82
- /// Returns a `BoxPredicate` wrapper around this `Predicate` type.
83
- ///
84
- /// Returns a `BoxPredicate` wrapper around this `Predicate type. The
85
- /// `BoxPredicate` type has a number of useful properties:
86
- ///
87
- /// - It stores the inner predicate as a trait object, so the type of
88
- /// `BoxPredicate` will always be the same even if steps are added or
89
- /// removed from the predicate.
90
- /// - It is a common type, allowing it to be stored in vectors or other
91
- /// collection types.
92
- /// - It implements `Debug` and `Display`.
93
- ///
94
- /// # Examples
95
- ///
96
- /// ```
97
- /// use predicates::prelude::*;
98
- ///
99
- /// let predicates = vec![
100
- /// predicate::always().boxed(),
101
- /// predicate::never().boxed(),
102
- /// ];
103
- /// assert_eq!(true, predicates[0].eval(&4));
104
- /// assert_eq!(false, predicates[1].eval(&4));
105
- /// ```
106
- fn boxed ( self ) -> BoxPredicate < Item >
107
- where
108
- Self : Sized + Send + Sync + ' static ,
109
- {
110
- BoxPredicate :: new ( self )
111
- }
112
20
}
0 commit comments