From 16e635cdfbb6b041886d1bccd28fa5e7e34c9f47 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Sun, 23 Feb 2014 10:56:38 +1100 Subject: std: make .swap_remove return Option. This is one of the last raw "indexing" method on vectors that returns `T` instead of the Option. --- src/libstd/vec_ng.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/libstd/vec_ng.rs') 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 Vec { } #[inline] - pub fn swap_remove(&mut self, index: uint) -> T { + pub fn swap_remove(&mut self, index: uint) -> Option { 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 Drop for MoveItems { } } } - -- cgit 1.4.1-3-g733a5