Skip to content

Commit 7cac5c9

Browse files
authored
Update vec.rs
Added remove_from to vec.rs
1 parent c80c31a commit 7cac5c9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/libcollections/vec.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,17 @@ impl<T: PartialEq> Vec<T> {
12961296
pub fn dedup(&mut self) {
12971297
self.dedup_by(|a, b| a == b)
12981298
}
1299+
1300+
#[stable(feature = "rust1", since = "1.0.0")]
1301+
pub fn remove_item(&mut self, item: &T) -> Option<usize> {
1302+
let pos = match self.iter().position(|x| *x == *item) {
1303+
Some(x) => x,
1304+
None => return None,
1305+
};
1306+
1307+
self.remove(pos);
1308+
Some(pos)
1309+
}
12991310
}
13001311

13011312
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)