31
31
inner : Vec < T > ,
32
32
}
33
33
34
+ impl < T > ContainsPredicate < T >
35
+ where
36
+ T : Ord ,
37
+ {
38
+ /// Creates a new predicate that will return `true` when the given `variable` is
39
+ /// contained with the set of items provided.
40
+ ///
41
+ /// Note that this implementation requires `Item` to be `Ord`. The
42
+ /// `ContainsPredicate` uses a less efficient search algorithm but only
43
+ /// requires `Item` implement `PartialEq`. The implementation-specific
44
+ /// predicates will be deprecated when Rust supports trait specialization.
45
+ ///
46
+ /// # Examples
47
+ ///
48
+ /// ```
49
+ /// use predicates::prelude::*;
50
+ ///
51
+ /// let predicate_fn = predicate::contains(vec![1, 3, 5]).ord();
52
+ /// assert_eq!(true, predicate_fn.eval(&1));
53
+ /// assert_eq!(false, predicate_fn.eval(&2));
54
+ /// assert_eq!(true, predicate_fn.eval(&3));
55
+ /// assert_eq!(false, predicate_fn.eval(&4));
56
+ /// assert_eq!(true, predicate_fn.eval(&5));
57
+ /// ```
58
+ pub fn ord ( self ) -> OrdContainsPredicate < T > {
59
+ let mut items = self . inner ;
60
+ items. sort ( ) ;
61
+ OrdContainsPredicate { inner : items }
62
+ }
63
+ }
64
+
34
65
impl < T > Predicate < T > for ContainsPredicate < T >
35
66
where
36
67
T : PartialEq ,
80
111
/// requires `Item` implement `PartialEq`. The implementation-specific
81
112
/// predicates will be deprecated when Rust supports trait specialization.
82
113
///
83
- /// This is created by the `predicate::contains_ord ` function.
114
+ /// This is created by the `predicate::contains(...).ord ` function.
84
115
#[ derive( Debug ) ]
85
116
pub struct OrdContainsPredicate < T >
86
117
where
@@ -98,36 +129,6 @@ where
98
129
}
99
130
}
100
131
101
- /// Creates a new predicate that will return `true` when the given `variable` is
102
- /// contained with the set of items provided.
103
- ///
104
- /// Note that this implementation requires `Item` to be `Ord`. The
105
- /// `ContainsPredicate` uses a less efficient search algorithm but only
106
- /// requires `Item` implement `PartialEq`. The implementation-specific
107
- /// predicates will be deprecated when Rust supports trait specialization.
108
- ///
109
- /// # Examples
110
- ///
111
- /// ```
112
- /// use predicates::prelude::*;
113
- ///
114
- /// let predicate_fn = predicate::contains_ord(vec![1, 3, 5]);
115
- /// assert_eq!(true, predicate_fn.eval(&1));
116
- /// assert_eq!(false, predicate_fn.eval(&2));
117
- /// assert_eq!(true, predicate_fn.eval(&3));
118
- /// assert_eq!(false, predicate_fn.eval(&4));
119
- /// assert_eq!(true, predicate_fn.eval(&5));
120
- /// ```
121
- pub fn contains_ord < I , T > ( iter : I ) -> OrdContainsPredicate < T >
122
- where
123
- T : Ord ,
124
- I : IntoIterator < Item = T > ,
125
- {
126
- let mut items = Vec :: from_iter ( iter) ;
127
- items. sort ( ) ;
128
- OrdContainsPredicate { inner : items }
129
- }
130
-
131
132
/// Predicate that returns `true` if `variable` is a member of the pre-defined
132
133
/// `HashSet`, otherwise returns `false`.
133
134
///
0 commit comments