From c09dac10738791460ff4897f5b3d12b62b2be9cc Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sat, 4 Jan 2020 23:31:32 +0530 Subject: add partial eq bound to remove_item --- src/liballoc/vec.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/liballoc/vec.rs') 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 Vec { pub fn dedup(&mut self) { self.dedup_by(|a, b| a == b) } +} + +impl Vec { /// Removes the first instance of `item` from the vector if the item exists. /// @@ -1701,11 +1704,15 @@ impl Vec { /// /// 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 { + pub fn remove_item(&mut self, item: &V) -> Option + where T: PartialEq + { let pos = self.iter().position(|x| *x == *item)?; Some(self.remove(pos)) } + } //////////////////////////////////////////////////////////////////////////////// -- cgit 1.4.1-3-g733a5 From f744ea03b46e860decb8672dc032805cbf9df652 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sat, 4 Jan 2020 23:57:34 +0530 Subject: ef em ti ... :P --- src/liballoc/tests/vec.rs | 6 +++--- src/liballoc/vec.rs | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src/liballoc/vec.rs') diff --git a/src/liballoc/tests/vec.rs b/src/liballoc/tests/vec.rs index bf4a31c72dd..2a9bfefc713 100644 --- a/src/liballoc/tests/vec.rs +++ b/src/liballoc/tests/vec.rs @@ -133,13 +133,13 @@ fn test_extend_ref() { #[test] fn test_remove_item() { - let mut v = vec![1,2,3]; + let mut v = vec![1, 2, 3]; v.remove_item(&1); assert_eq!(v.len(), 2); - assert_eq!(v, [2,3]); + assert_eq!(v, [2, 3]); - let mut w = vec![1,2,3]; + let mut w = vec![1, 2, 3]; w.remove_item(&4); assert_eq!(w.len(), 3); diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 0825dc228d8..9b48c21728a 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -1690,8 +1690,7 @@ impl Vec { } } -impl Vec { - +impl Vec { /// Removes the first instance of `item` from the vector if the item exists. /// /// # Examples @@ -1707,12 +1706,12 @@ impl Vec { #[unstable(feature = "vec_remove_item", reason = "recently added", issue = "40062")] pub fn remove_item(&mut self, item: &V) -> Option - where T: PartialEq + where + T: PartialEq, { let pos = self.iter().position(|x| *x == *item)?; Some(self.remove(pos)) } - } //////////////////////////////////////////////////////////////////////////////// -- cgit 1.4.1-3-g733a5 From 358b8983f2aae3dc8d2d08189eea8fd41898bb41 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sun, 5 Jan 2020 00:00:40 +0530 Subject: removed blank line --- src/liballoc/vec.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'src/liballoc/vec.rs') diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 9b48c21728a..a27a13847d6 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -1703,7 +1703,6 @@ impl Vec { /// /// assert_eq!(vec, vec![2, 3, 1]); /// ``` - #[unstable(feature = "vec_remove_item", reason = "recently added", issue = "40062")] pub fn remove_item(&mut self, item: &V) -> Option where -- cgit 1.4.1-3-g733a5