diff --git a/src/lib.rs b/src/lib.rs index cd7f46c..c7727b2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -403,7 +403,7 @@ impl ArrayVec { /// assert_eq!(&array[..], &[2, 3]); /// ``` pub fn remove(&mut self, index: usize) -> A::Item { - self.remove_opt(index) + self.pop_at(index) .unwrap_or_else(|| { panic_oob!("remove", index, self.len()) }) @@ -411,22 +411,21 @@ impl ArrayVec { /// Remove the element at `index` and shift down the following elements. /// - /// This is a checked version of `.remove(index)`. Returns `None` if the - /// index is greater or equal to the length of the vector. Otherwise, return - /// the element inside `Some`. + /// This is a checked version of `.remove(index)`. Returns `None` if there + /// is no element at `index`. Otherwise, return the element inside `Some`. /// /// ``` /// use arrayvec::ArrayVec; /// /// let mut array = ArrayVec::from([1, 2, 3]); /// - /// assert!(array.remove_opt(0).is_some()); + /// assert!(array.pop_at(0).is_some()); /// assert_eq!(&array[..], &[2, 3]); /// - /// assert!(array.remove_opt(2).is_none()); - /// assert!(array.remove_opt(10).is_none()); + /// assert!(array.pop_at(2).is_none()); + /// assert!(array.pop_at(10).is_none()); /// ``` - pub fn remove_opt(&mut self, index: usize) -> Option { + pub fn pop_at(&mut self, index: usize) -> Option { if index >= self.len() { None } else { diff --git a/tests/tests.rs b/tests/tests.rs index 66529c9..7db5529 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -434,3 +434,19 @@ fn test_drop_in_insert() { } assert_eq!(flag.get(), 3); } + +#[test] +fn test_pop_at() { + let mut v = ArrayVec::<[String; 4]>::new(); + let s = String::from; + v.push(s("a")); + v.push(s("b")); + v.push(s("c")); + v.push(s("d")); + + assert_eq!(v.pop_at(4), None); + assert_eq!(v.pop_at(1), Some(s("b"))); + assert_eq!(v.pop_at(1), Some(s("c"))); + assert_eq!(v.pop_at(2), None); + assert_eq!(&v[..], &["a", "d"]); +}