diff options
| author | dylan_DPC <dylan.dpc@gmail.com> | 2020-01-04 23:31:32 +0530 |
|---|---|---|
| committer | dylan_DPC <dylan.dpc@gmail.com> | 2020-01-04 23:31:32 +0530 |
| commit | c09dac10738791460ff4897f5b3d12b62b2be9cc (patch) | |
| tree | 0176f27781832a0a5368229395429184243ee926 /src/liballoc | |
| parent | abf2e00e38ad404d563f03acbcf06b08813fd086 (diff) | |
| download | rust-c09dac10738791460ff4897f5b3d12b62b2be9cc.tar.gz rust-c09dac10738791460ff4897f5b3d12b62b2be9cc.zip | |
add partial eq bound to remove_item
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/vec.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 93a51ccb207..0825dc228d8 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -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)) } + } //////////////////////////////////////////////////////////////////////////////// |
