@@ -1315,6 +1315,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
13151315 ///
13161316 /// If [`make_contiguous`] was previously called, all elements of the
13171317 /// deque will be in the first slice and the second slice will be empty.
1318+ /// Otherwise, the exact split point depends on implementation details
1319+ /// and is not guaranteed.
13181320 ///
13191321 /// [`make_contiguous`]: VecDeque::make_contiguous
13201322 ///
@@ -1329,12 +1331,18 @@ impl<T, A: Allocator> VecDeque<T, A> {
13291331 /// deque.push_back(1);
13301332 /// deque.push_back(2);
13311333 ///
1332- /// assert_eq!(deque.as_slices(), (&[0, 1, 2][..], &[][..]));
1334+ /// let expected = [0, 1, 2];
1335+ /// let (front, back) = deque.as_slices();
1336+ /// assert_eq!(&expected[..front.len()], front);
1337+ /// assert_eq!(&expected[front.len()..], back);
13331338 ///
13341339 /// deque.push_front(10);
13351340 /// deque.push_front(9);
13361341 ///
1337- /// assert_eq!(deque.as_slices(), (&[9, 10][..], &[0, 1, 2][..]));
1342+ /// let expected = [9, 10, 0, 1, 2];
1343+ /// let (front, back) = deque.as_slices();
1344+ /// assert_eq!(&expected[..front.len()], front);
1345+ /// assert_eq!(&expected[front.len()..], back);
13381346 /// ```
13391347 #[ inline]
13401348 #[ stable( feature = "deque_extras_15" , since = "1.5.0" ) ]
@@ -1350,6 +1358,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
13501358 ///
13511359 /// If [`make_contiguous`] was previously called, all elements of the
13521360 /// deque will be in the first slice and the second slice will be empty.
1361+ /// Otherwise, the exact split point depends on implementation details
1362+ /// and is not guaranteed.
13531363 ///
13541364 /// [`make_contiguous`]: VecDeque::make_contiguous
13551365 ///
@@ -1366,9 +1376,22 @@ impl<T, A: Allocator> VecDeque<T, A> {
13661376 /// deque.push_front(10);
13671377 /// deque.push_front(9);
13681378 ///
1369- /// deque.as_mut_slices().0[0] = 42;
1370- /// deque.as_mut_slices().1[0] = 24;
1371- /// assert_eq!(deque.as_slices(), (&[42, 10][..], &[24, 1][..]));
1379+ /// // Since the split point is not guaranteed, we may need to update
1380+ /// // either slice.
1381+ /// let mut update_nth = |index: usize, val: u32| {
1382+ /// let (front, back) = deque.as_mut_slices();
1383+ /// if index > front.len() - 1 {
1384+ /// back[index - front.len()] = val;
1385+ /// } else {
1386+ /// front[index] = val;
1387+ /// }
1388+ /// };
1389+ ///
1390+ /// update_nth(0, 42);
1391+ /// update_nth(2, 24);
1392+ ///
1393+ /// let v: Vec<_> = deque.into();
1394+ /// assert_eq!(v, [42, 10, 24, 1]);
13721395 /// ```
13731396 #[ inline]
13741397 #[ stable( feature = "deque_extras_15" , since = "1.5.0" ) ]
0 commit comments