Skip to content

Commit d6f87ba

Browse files
committed
add example to prepend
1 parent de1aa71 commit d6f87ba

File tree

1 file changed

+14
-1
lines changed
  • library/alloc/src/collections/vec_deque

1 file changed

+14
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1975,7 +1975,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
19751975
/// The order of the contents is preserved.
19761976
///
19771977
/// To get behavior like [`append`][VecDeque::append] where elements are moved
1978-
/// from the other collection to this one, use `self.prepend(other.drain())`.
1978+
/// from the other collection to this one, use `self.prepend(other.drain(..))`.
19791979
///
19801980
/// # Examples
19811981
///
@@ -1987,6 +1987,19 @@ impl<T, A: Allocator> VecDeque<T, A> {
19871987
/// deque.prepend([1, 2, 3]);
19881988
/// assert_eq!(deque, [1, 2, 3, 4, 5, 6]);
19891989
/// ```
1990+
///
1991+
/// Move values between collections like [`append`][VecDeque::append] does but prepend to the front:
1992+
///
1993+
/// ```
1994+
/// #![feature(deque_extend_front)]
1995+
/// use std::collections::VecDeque;
1996+
///
1997+
/// let mut deque1 = VecDeque::from([4, 5, 6]);
1998+
/// let mut deque2 = VecDeque::from([1, 2, 3]);
1999+
/// deque1.prepend(deque2.drain(..));
2000+
/// assert_eq!(deque1, [1, 2, 3, 4, 5, 6]);
2001+
/// assert!(deque2.is_empty());
2002+
/// ```
19902003
#[unstable(feature = "deque_extend_front", issue = "146975")]
19912004
#[track_caller]
19922005
pub fn prepend<I: IntoIterator<Item = T, IntoIter: DoubleEndedIterator>>(&mut self, other: I) {

0 commit comments

Comments
 (0)