Skip to content

Commit 3905e10

Browse files
committed
feat(iter): Merge contains_ord into contains
Reducing API footprint in prep for renaming. BREAKING CHANGE: `predicates::iter::contains_ord` -> `predicates::iter::contains(...).ord()`
1 parent 2f6ab4a commit 3905e10

File tree

2 files changed

+33
-32
lines changed

2 files changed

+33
-32
lines changed

src/iter.rs

+32-31
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,37 @@ where
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+
3465
impl<T> Predicate<T> for ContainsPredicate<T>
3566
where
3667
T: PartialEq,
@@ -80,7 +111,7 @@ where
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)]
85116
pub struct OrdContainsPredicate<T>
86117
where
@@ -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
///

src/prelude.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub mod predicate {
1616
pub use constant::{always, never};
1717
pub use function::function;
1818
pub use ord::{eq, ge, gt, le, lt, ne};
19-
pub use iter::{contains, contains_hashable, contains_ord};
19+
pub use iter::{contains, contains_hashable};
2020

2121
/// `str` Predicate factories
2222
///

0 commit comments

Comments
 (0)