@@ -1312,6 +1312,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
13121312///
13131313/// If [`make_contiguous`] was previously called, all elements of the
13141314/// deque will be in the first slice and the second slice will be empty.
1315+ /// Otherwise, the exact split point depends on implementation details
1316+ /// and is not guaranteed.
13151317///
13161318/// [`make_contiguous`]: VecDeque::make_contiguous
13171319///
@@ -1326,12 +1328,18 @@ impl<T, A: Allocator> VecDeque<T, A> {
13261328/// deque.push_back(1);
13271329/// deque.push_back(2);
13281330///
1329- /// assert_eq!(deque.as_slices(), (&[0, 1, 2][..], &[][..]));
1331+ /// let expected = [0, 1, 2];
1332+ /// let (front, back) = deque.as_slices();
1333+ /// assert_eq!(&expected[..front.len()], front);
1334+ /// assert_eq!(&expected[front.len()..], back);
13301335///
13311336/// deque.push_front(10);
13321337/// deque.push_front(9);
13331338///
1334- /// assert_eq!(deque.as_slices(), (&[9, 10][..], &[0, 1, 2][..]));
1339+ /// let expected = [9, 10, 0, 1, 2];
1340+ /// let (front, back) = deque.as_slices();
1341+ /// assert_eq!(&expected[..front.len()], front);
1342+ /// assert_eq!(&expected[front.len()..], back);
13351343/// ```
13361344#[ inline]
13371345#[ stable( feature = "deque_extras_15" , since = "1.5.0" ) ]
@@ -1347,6 +1355,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
13471355///
13481356/// If [`make_contiguous`] was previously called, all elements of the
13491357/// deque will be in the first slice and the second slice will be empty.
1358+ /// Otherwise, the exact split point depends on implementation details
1359+ /// and is not guaranteed.
13501360///
13511361/// [`make_contiguous`]: VecDeque::make_contiguous
13521362///
@@ -1363,9 +1373,22 @@ impl<T, A: Allocator> VecDeque<T, A> {
13631373/// deque.push_front(10);
13641374/// deque.push_front(9);
13651375///
1366- /// deque.as_mut_slices().0[0] = 42;
1367- /// deque.as_mut_slices().1[0] = 24;
1368- /// assert_eq!(deque.as_slices(), (&[42, 10][..], &[24, 1][..]));
1376+ /// // Since the split point is not guaranteed, we may need to update
1377+ /// // either slice.
1378+ /// let mut update_nth = |index: usize, val: u32| {
1379+ /// let (front, back) = deque.as_mut_slices();
1380+ /// if index > front.len() - 1 {
1381+ /// back[index - front.len()] = val;
1382+ /// } else {
1383+ /// front[index] = val;
1384+ /// }
1385+ /// };
1386+ ///
1387+ /// update_nth(0, 42);
1388+ /// update_nth(2, 24);
1389+ ///
1390+ /// let v: Vec<_> = deque.into();
1391+ /// assert_eq!(v, [42, 10, 24, 1]);
13691392/// ```
13701393#[ inline]
13711394#[ stable( feature = "deque_extras_15" , since = "1.5.0" ) ]
0 commit comments