@@ -1315,6 +1315,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
1315
1315
///
1316
1316
/// If [`make_contiguous`] was previously called, all elements of the
1317
1317
/// 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.
1318
1320
///
1319
1321
/// [`make_contiguous`]: VecDeque::make_contiguous
1320
1322
///
@@ -1329,12 +1331,18 @@ impl<T, A: Allocator> VecDeque<T, A> {
1329
1331
/// deque.push_back(1);
1330
1332
/// deque.push_back(2);
1331
1333
///
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);
1333
1338
///
1334
1339
/// deque.push_front(10);
1335
1340
/// deque.push_front(9);
1336
1341
///
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);
1338
1346
/// ```
1339
1347
#[ inline]
1340
1348
#[ stable( feature = "deque_extras_15" , since = "1.5.0" ) ]
@@ -1350,6 +1358,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
1350
1358
///
1351
1359
/// If [`make_contiguous`] was previously called, all elements of the
1352
1360
/// 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.
1353
1363
///
1354
1364
/// [`make_contiguous`]: VecDeque::make_contiguous
1355
1365
///
@@ -1366,9 +1376,22 @@ impl<T, A: Allocator> VecDeque<T, A> {
1366
1376
/// deque.push_front(10);
1367
1377
/// deque.push_front(9);
1368
1378
///
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]);
1372
1395
/// ```
1373
1396
#[ inline]
1374
1397
#[ stable( feature = "deque_extras_15" , since = "1.5.0" ) ]
0 commit comments