Skip to content

Commit 7bdd978

Browse files
authored
Rollup merge of #92977 - kornelski:popdoc, r=dtolnay
Docs: recommend VecDeque instead of Vec::remove(0) Suggestion based on a [discussion](https://internals.rust-lang.org/t/should-vec-have-a-try-remove-mut-self-usize-option-t-function/15964/9?u=kornel) where user needlessly struggled with `remove(0)` and accidentally created a quadratic cost.
2 parents 775fe37 + 361ef2a commit 7bdd978

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

library/alloc/src/vec/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1372,9 +1372,12 @@ impl<T, A: Allocator> Vec<T, A> {
13721372
///
13731373
/// Note: Because this shifts over the remaining elements, it has a
13741374
/// worst-case performance of *O*(*n*). If you don't need the order of elements
1375-
/// to be preserved, use [`swap_remove`] instead.
1375+
/// to be preserved, use [`swap_remove`] instead. If you'd like to remove
1376+
/// elements from the beginning of the `Vec`, consider using
1377+
/// [`VecDeque::pop_front`] instead.
13761378
///
13771379
/// [`swap_remove`]: Vec::swap_remove
1380+
/// [`VecDeque::pop_front`]: crate::collections::VecDeque::pop_front
13781381
///
13791382
/// # Panics
13801383
///
@@ -1735,6 +1738,11 @@ impl<T, A: Allocator> Vec<T, A> {
17351738
/// Removes the last element from a vector and returns it, or [`None`] if it
17361739
/// is empty.
17371740
///
1741+
/// If you'd like to pop the first element, consider using
1742+
/// [`VecDeque::pop_front`] instead.
1743+
///
1744+
/// [`VecDeque::pop_front`]: crate::collections::VecDeque::pop_front
1745+
///
17381746
/// # Examples
17391747
///
17401748
/// ```

0 commit comments

Comments
 (0)