@@ -1312,6 +1312,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
1312
1312
///
1313
1313
/// If [`make_contiguous`] was previously called, all elements of the
1314
1314
/// 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.
1315
1317
///
1316
1318
/// [`make_contiguous`]: VecDeque::make_contiguous
1317
1319
///
@@ -1326,12 +1328,18 @@ impl<T, A: Allocator> VecDeque<T, A> {
1326
1328
/// deque.push_back(1);
1327
1329
/// deque.push_back(2);
1328
1330
///
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);
1330
1335
///
1331
1336
/// deque.push_front(10);
1332
1337
/// deque.push_front(9);
1333
1338
///
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);
1335
1343
/// ```
1336
1344
#[ inline]
1337
1345
#[ stable( feature = "deque_extras_15" , since = "1.5.0" ) ]
@@ -1347,6 +1355,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
1347
1355
///
1348
1356
/// If [`make_contiguous`] was previously called, all elements of the
1349
1357
/// 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.
1350
1360
///
1351
1361
/// [`make_contiguous`]: VecDeque::make_contiguous
1352
1362
///
@@ -1363,9 +1373,22 @@ impl<T, A: Allocator> VecDeque<T, A> {
1363
1373
/// deque.push_front(10);
1364
1374
/// deque.push_front(9);
1365
1375
///
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]);
1369
1392
/// ```
1370
1393
#[ inline]
1371
1394
#[ stable( feature = "deque_extras_15" , since = "1.5.0" ) ]
0 commit comments