Skip to content

Commit c09dac1

Browse files
committed
add partial eq bound to remove_item
1 parent abf2e00 commit c09dac1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/liballoc/vec.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,9 @@ impl<T: PartialEq> Vec<T> {
16881688
pub fn dedup(&mut self) {
16891689
self.dedup_by(|a, b| a == b)
16901690
}
1691+
}
1692+
1693+
impl <T> Vec<T> {
16911694

16921695
/// Removes the first instance of `item` from the vector if the item exists.
16931696
///
@@ -1701,11 +1704,15 @@ impl<T: PartialEq> Vec<T> {
17011704
///
17021705
/// assert_eq!(vec, vec![2, 3, 1]);
17031706
/// ```
1707+
17041708
#[unstable(feature = "vec_remove_item", reason = "recently added", issue = "40062")]
1705-
pub fn remove_item(&mut self, item: &T) -> Option<T> {
1709+
pub fn remove_item<V>(&mut self, item: &V) -> Option<T>
1710+
where T: PartialEq<V>
1711+
{
17061712
let pos = self.iter().position(|x| *x == *item)?;
17071713
Some(self.remove(pos))
17081714
}
1715+
17091716
}
17101717

17111718
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)