diff options
| author | bors <bors@rust-lang.org> | 2017-01-09 17:31:41 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-01-09 17:31:41 +0000 |
| commit | 5c1472a720243314ac5e659f3d621242eb82f2de (patch) | |
| tree | 86c575c49328a97e66c3b0fad09f27d8b7d48d1a | |
| parent | bd16aa08cdfb89982e3ed2820454769321803c61 (diff) | |
| parent | 0ab781214c3bc9a70a47c576406646b4361769e6 (diff) | |
| download | rust-5c1472a720243314ac5e659f3d621242eb82f2de.tar.gz rust-5c1472a720243314ac5e659f3d621242eb82f2de.zip | |
Auto merge of #38581 - frewsxcv:vecdequeue-insert, r=GuillaumeGomez
Clarify behavior of `VecDeque::insert`. Fixes https://github.com/rust-lang/rust/issues/37046.
| -rw-r--r-- | src/libcollections/vec_deque.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/libcollections/vec_deque.rs b/src/libcollections/vec_deque.rs index 67621b860bf..d650360435a 100644 --- a/src/libcollections/vec_deque.rs +++ b/src/libcollections/vec_deque.rs @@ -1228,9 +1228,8 @@ impl<T> VecDeque<T> { self.pop_front() } - /// Inserts an element at `index` within the `VecDeque`. Whichever - /// end is closer to the insertion point will be moved to make room, - /// and all the affected elements will be moved to new positions. + /// Inserts an element at `index` within the `VecDeque`, shifting all elements with indices + /// greater than or equal to `index` towards the back. /// /// Element at index 0 is the front of the queue. /// @@ -1239,14 +1238,19 @@ impl<T> VecDeque<T> { /// Panics if `index` is greater than `VecDeque`'s length /// /// # Examples + /// /// ``` /// use std::collections::VecDeque; /// - /// let mut buf = VecDeque::new(); - /// buf.push_back(10); - /// buf.push_back(12); - /// buf.insert(1, 11); - /// assert_eq!(Some(&11), buf.get(1)); + /// let mut vec_deque = VecDeque::new(); + /// vec_deque.push_back('a'); + /// vec_deque.push_back('b'); + /// vec_deque.push_back('c'); + /// + /// vec_deque.insert(1, 'd'); + /// + /// let vec = vec_deque.into_iter().collect::<Vec<_>>(); + /// assert_eq!(vec, ['a', 'd', 'b', 'c']); /// ``` #[stable(feature = "deque_extras_15", since = "1.5.0")] pub fn insert(&mut self, index: usize, value: T) { |
