add partial eq bound to remove_item
This commit is contained in:
parent
abf2e00e38
commit
c09dac1073
1 changed files with 8 additions and 1 deletions
|
@ -1688,6 +1688,9 @@ impl<T: PartialEq> Vec<T> {
|
|||
pub fn dedup(&mut self) {
|
||||
self.dedup_by(|a, b| a == b)
|
||||
}
|
||||
}
|
||||
|
||||
impl <T> Vec<T> {
|
||||
|
||||
/// Removes the first instance of `item` from the vector if the item exists.
|
||||
///
|
||||
|
@ -1701,11 +1704,15 @@ impl<T: PartialEq> Vec<T> {
|
|||
///
|
||||
/// assert_eq!(vec, vec![2, 3, 1]);
|
||||
/// ```
|
||||
|
||||
#[unstable(feature = "vec_remove_item", reason = "recently added", issue = "40062")]
|
||||
pub fn remove_item(&mut self, item: &T) -> Option<T> {
|
||||
pub fn remove_item<V>(&mut self, item: &V) -> Option<T>
|
||||
where T: PartialEq<V>
|
||||
{
|
||||
let pos = self.iter().position(|x| *x == *item)?;
|
||||
Some(self.remove(pos))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue