3131 inner : Vec < T > ,
3232}
3333
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+
3465impl < T > Predicate < T > for ContainsPredicate < T >
3566where
3667 T : PartialEq ,
80111/// requires `Item` implement `PartialEq`. The implementation-specific
81112/// predicates will be deprecated when Rust supports trait specialization.
82113///
83- /// This is created by the `predicate::contains_ord ` function.
114+ /// This is created by the `predicate::contains(...).ord ` function.
84115#[ derive( Debug ) ]
85116pub struct OrdContainsPredicate < T >
86117where
@@ -98,36 +129,6 @@ where
98129 }
99130}
100131
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-
131132/// Predicate that returns `true` if `variable` is a member of the pre-defined
132133/// `HashSet`, otherwise returns `false`.
133134///
0 commit comments