Skip to content

Commit 9a2e3f3

Browse files
committed
Recommend swap_remove in Vec::remove docs
1 parent f3f8e75 commit 9a2e3f3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

library/alloc/src/vec/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,12 @@ impl<T, A: Allocator> Vec<T, A> {
13601360
/// Removes and returns the element at position `index` within the vector,
13611361
/// shifting all elements after it to the left.
13621362
///
1363+
/// Note: Because this shifts over the remaining elements, it has a
1364+
/// worst-case performance of O(n). If you don't need the order of elements
1365+
/// to be preserved, use [`swap_remove`] instead.
1366+
///
1367+
/// [`swap_remove`]: Vec::swap_remove
1368+
///
13631369
/// # Panics
13641370
///
13651371
/// Panics if `index` is out of bounds.

0 commit comments

Comments
 (0)