1
Fork 0

std: make .swap_remove return Option<T>.

This is one of the last raw "indexing" method on vectors that returns
`T` instead of the Option.
This commit is contained in:
Huon Wilson 2014-02-23 10:56:38 +11:00 committed by Alex Crichton
parent 3ca01676bc
commit 16e635cdfb
3 changed files with 35 additions and 27 deletions

View file

@ -277,15 +277,14 @@ impl<T> Vec<T> {
}
#[inline]
pub fn swap_remove(&mut self, index: uint) -> T {
pub fn swap_remove(&mut self, index: uint) -> Option<T> {
let length = self.len();
if index >= length {
fail!("Vec::swap_remove - index {} >= length {}", index, length);
}
if index < length - 1 {
self.as_mut_slice().swap(index, length - 1);
} else if index >= length {
return None
}
self.pop().unwrap()
self.pop()
}
#[inline]
@ -392,4 +391,3 @@ impl<T> Drop for MoveItems<T> {
}
}
}