diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2014-02-23 10:56:38 +1100 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-02-24 21:22:26 -0800 |
| commit | 16e635cdfbb6b041886d1bccd28fa5e7e34c9f47 (patch) | |
| tree | eae398f604ca7c7798707ec1fd935fef79a0a493 /src/libstd/vec_ng.rs | |
| parent | 3ca01676bcbd092b04608cc0eee843b7031e46cb (diff) | |
| download | rust-16e635cdfbb6b041886d1bccd28fa5e7e34c9f47.tar.gz rust-16e635cdfbb6b041886d1bccd28fa5e7e34c9f47.zip | |
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.
Diffstat (limited to 'src/libstd/vec_ng.rs')
| -rw-r--r-- | src/libstd/vec_ng.rs | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/libstd/vec_ng.rs b/src/libstd/vec_ng.rs index 3532e7b26a4..2f39adc25d3 100644 --- a/src/libstd/vec_ng.rs +++ b/src/libstd/vec_ng.rs @@ -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> { } } } - |
