Skip to content

Commit 5c1472a

Browse files
committed
Auto merge of #38581 - frewsxcv:vecdequeue-insert, r=GuillaumeGomez
Clarify behavior of `VecDeque::insert`. Fixes #37046.
2 parents bd16aa0 + 0ab7812 commit 5c1472a

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/libcollections/vec_deque.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -1228,9 +1228,8 @@ impl<T> VecDeque<T> {
12281228
self.pop_front()
12291229
}
12301230

1231-
/// Inserts an element at `index` within the `VecDeque`. Whichever
1232-
/// end is closer to the insertion point will be moved to make room,
1233-
/// and all the affected elements will be moved to new positions.
1231+
/// Inserts an element at `index` within the `VecDeque`, shifting all elements with indices
1232+
/// greater than or equal to `index` towards the back.
12341233
///
12351234
/// Element at index 0 is the front of the queue.
12361235
///
@@ -1239,14 +1238,19 @@ impl<T> VecDeque<T> {
12391238
/// Panics if `index` is greater than `VecDeque`'s length
12401239
///
12411240
/// # Examples
1241+
///
12421242
/// ```
12431243
/// use std::collections::VecDeque;
12441244
///
1245-
/// let mut buf = VecDeque::new();
1246-
/// buf.push_back(10);
1247-
/// buf.push_back(12);
1248-
/// buf.insert(1, 11);
1249-
/// assert_eq!(Some(&11), buf.get(1));
1245+
/// let mut vec_deque = VecDeque::new();
1246+
/// vec_deque.push_back('a');
1247+
/// vec_deque.push_back('b');
1248+
/// vec_deque.push_back('c');
1249+
///
1250+
/// vec_deque.insert(1, 'd');
1251+
///
1252+
/// let vec = vec_deque.into_iter().collect::<Vec<_>>();
1253+
/// assert_eq!(vec, ['a', 'd', 'b', 'c']);
12501254
/// ```
12511255
#[stable(feature = "deque_extras_15", since = "1.5.0")]
12521256
pub fn insert(&mut self, index: usize, value: T) {

0 commit comments

Comments
 (0)