Skip to content

Commit a1bfdfa

Browse files
committed
add prepend, improve doc and add tracking issue number
1 parent 1fbeacf commit a1bfdfa

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
@@ -1971,7 +1971,28 @@ impl<T, A: Allocator> VecDeque<T, A> {
19711971
unsafe { self.buffer_write(self.to_physical_idx(len), value) }
19721972
}
19731973

1974-
/// 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.
1974+
/// Prepends all contents of the iterator to the front of the deque.
1975+
/// The order of the contents is preserved.
1976+
///
1977+
/// # Examples
1978+
///
1979+
/// ```
1980+
/// #![feature(deque_extend_front)]
1981+
/// use std::collections::VecDeque;
1982+
///
1983+
/// let mut deque = VecDeque::from([4, 5, 6]);
1984+
/// deque.prepend([1, 2, 3]);
1985+
/// assert_eq!(deque, [1, 2, 3, 4, 5, 6]);
1986+
/// ```
1987+
#[unstable(feature = "deque_extend_front", issue = "146975")]
1988+
#[track_caller]
1989+
pub fn prepend<I: IntoIterator<Item = T, IntoIter: DoubleEndedIterator>>(&mut self, other: I) {
1990+
self.extend_front(other.into_iter().rev())
1991+
}
1992+
1993+
/// Prepends all contents of the iterator to the front of the deque,
1994+
/// as if [`push_front`][VecDeque::push_front] was called repeatedly with
1995+
/// the values yielded by the iterator.
19751996
///
19761997
/// # Examples
19771998
///
@@ -1983,7 +2004,19 @@ impl<T, A: Allocator> VecDeque<T, A> {
19832004
/// deque.extend_front([3, 2, 1]);
19842005
/// assert_eq!(deque, [1, 2, 3, 4, 5, 6]);
19852006
/// ```
1986-
#[unstable(feature = "deque_extend_front", issue = "none")]
2007+
///
2008+
/// This behaves like [`push_front`][VecDeque::push_front] was called repeatedly:
2009+
///
2010+
/// ```
2011+
/// use std::collections::VecDeque;
2012+
///
2013+
/// let mut deque = VecDeque::from([4, 5, 6]);
2014+
/// for v in [3, 2, 1] {
2015+
/// deque.push_front(v);
2016+
/// }
2017+
/// assert_eq!(deque, [1, 2, 3, 4, 5, 6]);
2018+
/// ```
2019+
#[unstable(feature = "deque_extend_front", issue = "146975")]
19872020
#[track_caller]
19882021
pub fn extend_front<I: IntoIterator<Item = T>>(&mut self, iter: I) {
19892022
<Self as SpecExtendFront<T, I::IntoIter>>::spec_extend_front(self, iter.into_iter());

0 commit comments

Comments
 (0)