File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -1335,6 +1335,27 @@ impl<T: PartialEq> Vec<T> {
13351335 pub fn dedup ( & mut self ) {
13361336 self . dedup_by ( |a, b| a == b)
13371337 }
1338+
1339+ /// Removes the first instance of `item` from the vector if the item exists.
1340+ ///
1341+ /// # Examples
1342+ ///
1343+ /// ```
1344+ ///# #![feature(vec_remove_item)]
1345+ /// let mut vec = vec![1, 2, 3, 1];
1346+ ///
1347+ /// vec.remove_item(&1);
1348+ ///
1349+ /// assert_eq!(vec, vec![2, 3, 1]);
1350+ /// ```
1351+ #[ unstable( feature = "vec_remove_item" , reason = "recently added" , issue = "40062" ) ]
1352+ pub fn remove_item ( & mut self , item : & T ) -> Option < T > {
1353+ let pos = match self . iter ( ) . position ( |x| * x == * item) {
1354+ Some ( x) => x,
1355+ None => return None ,
1356+ } ;
1357+ Some ( self . remove ( pos) )
1358+ }
13381359}
13391360
13401361////////////////////////////////////////////////////////////////////////////////
You can’t perform that action at this time.
0 commit comments