File tree 1 file changed +21
-0
lines changed
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> {
1335
1335
pub fn dedup ( & mut self ) {
1336
1336
self . dedup_by ( |a, b| a == b)
1337
1337
}
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
+ }
1338
1359
}
1339
1360
1340
1361
////////////////////////////////////////////////////////////////////////////////
You can’t perform that action at this time.
0 commit comments