Skip to content

Commit c5dfa22

Browse files
committed
add prepend, improve doc and add tracking issue number
1 parent 6da1b60 commit c5dfa22

File tree

1 file changed

+35
-2
lines changed
  • library/alloc/src/collections/vec_deque

1 file changed

+35
-2
lines changed

library/alloc/src/collections/vec_deque/mod.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,7 +1983,28 @@ impl<T, A: Allocator> VecDeque<T, A> {
19831983
unsafe { self.buffer_write(self.to_physical_idx(len), value) }
19841984
}
19851985

1986-
/// Prepends all elements from the iterator to the front of the deque, as if [`push_front`][VecDeque::push_front] was called with the elements of the iterator.
1986+
/// Prepends all contents of the iterator to the front of the deque.
1987+
/// The order of the contents is preserved.
1988+
///
1989+
/// # Examples
1990+
///
1991+
/// ```
1992+
/// #![feature(deque_extend_front)]
1993+
/// use std::collections::VecDeque;
1994+
///
1995+
/// let mut deque = VecDeque::from([4, 5, 6]);
1996+
/// deque.prepend([1, 2, 3]);
1997+
/// assert_eq!(deque, [1, 2, 3, 4, 5, 6]);
1998+
/// ```
1999+
#[unstable(feature = "deque_extend_front", issue = "146975")]
2000+
#[track_caller]
2001+
pub fn prepend<I: IntoIterator<Item = T, IntoIter: DoubleEndedIterator>>(&mut self, other: I) {
2002+
self.extend_front(other.into_iter().rev())
2003+
}
2004+
2005+
/// Prepends all contents of the iterator to the front of the deque,
2006+
/// as if [`push_front`][VecDeque::push_front] was called repeatedly with
2007+
/// the values yielded by the iterator.
19872008
///
19882009
/// # Examples
19892010
///
@@ -1995,7 +2016,19 @@ impl<T, A: Allocator> VecDeque<T, A> {
19952016
/// deque.extend_front([3, 2, 1]);
19962017
/// assert_eq!(deque, [1, 2, 3, 4, 5, 6]);
19972018
/// ```
1998-
#[unstable(feature = "deque_extend_front", issue = "none")]
2019+
///
2020+
/// This behaves like [`push_front`][VecDeque::push_front] was called repeatedly:
2021+
///
2022+
/// ```
2023+
/// use std::collections::VecDeque;
2024+
///
2025+
/// let mut deque = VecDeque::from([4, 5, 6]);
2026+
/// for v in [3, 2, 1] {
2027+
/// deque.push_front(v);
2028+
/// }
2029+
/// assert_eq!(deque, [1, 2, 3, 4, 5, 6]);
2030+
/// ```
2031+
#[unstable(feature = "deque_extend_front", issue = "146975")]
19992032
#[track_caller]
20002033
pub fn extend_front<I: IntoIterator<Item = T>>(&mut self, iter: I) {
20012034
<Self as SpecExtendFront<T, I::IntoIter>>::spec_extend_front(self, iter.into_iter());

0 commit comments

Comments
 (0)