Skip to content

Commit 0ab7812

Browse files
committed
Clarify behavior of VecDeque::insert.
Fixes #37046.
1 parent 1b38776 commit 0ab7812

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
@@ -1232,9 +1232,8 @@ impl<T> VecDeque<T> {
12321232
self.pop_front()
12331233
}
12341234

1235-
/// Inserts an element at `index` within the `VecDeque`. Whichever
1236-
/// end is closer to the insertion point will be moved to make room,
1237-
/// and all the affected elements will be moved to new positions.
1235+
/// Inserts an element at `index` within the `VecDeque`, shifting all elements with indices
1236+
/// greater than or equal to `index` towards the back.
12381237
///
12391238
/// Element at index 0 is the front of the queue.
12401239
///
@@ -1243,14 +1242,19 @@ impl<T> VecDeque<T> {
12431242
/// Panics if `index` is greater than `VecDeque`'s length
12441243
///
12451244
/// # Examples
1245+
///
12461246
/// ```
12471247
/// use std::collections::VecDeque;
12481248
///
1249-
/// let mut buf = VecDeque::new();
1250-
/// buf.push_back(10);
1251-
/// buf.push_back(12);
1252-
/// buf.insert(1, 11);
1253-
/// assert_eq!(Some(&11), buf.get(1));
1249+
/// let mut vec_deque = VecDeque::new();
1250+
/// vec_deque.push_back('a');
1251+
/// vec_deque.push_back('b');
1252+
/// vec_deque.push_back('c');
1253+
///
1254+
/// vec_deque.insert(1, 'd');
1255+
///
1256+
/// let vec = vec_deque.into_iter().collect::<Vec<_>>();
1257+
/// assert_eq!(vec, ['a', 'd', 'b', 'c']);
12541258
/// ```
12551259
#[stable(feature = "deque_extras_15", since = "1.5.0")]
12561260
pub fn insert(&mut self, index: usize, value: T) {

0 commit comments

Comments
 (0)