@@ -1262,6 +1262,18 @@ impl<T> [T] {
1262
1262
/// Splits the slice into a slice of `N`-element arrays,
1263
1263
/// assuming that there's no remainder.
1264
1264
///
1265
+ /// This is the inverse operation to [`as_flattened`].
1266
+ ///
1267
+ /// [`as_flattened`]: slice::as_flattened
1268
+ ///
1269
+ /// As this is `unsafe`, consider whether you could use [`as_chunks`] or
1270
+ /// [`as_rchunks`] instead, perhaps via something like
1271
+ /// `if let (chunks, []) = slice.as_chunks()` or
1272
+ /// `let (chunks, []) = slice.as_chunks() else { unreachable!() };`.
1273
+ ///
1274
+ /// [`as_chunks`]: slice::as_chunks
1275
+ /// [`as_rchunks`]: slice::as_rchunks
1276
+ ///
1265
1277
/// # Safety
1266
1278
///
1267
1279
/// This may only be called when
@@ -1306,10 +1318,23 @@ impl<T> [T] {
1306
1318
/// starting at the beginning of the slice,
1307
1319
/// and a remainder slice with length strictly less than `N`.
1308
1320
///
1321
+ /// The remainder is meaningful in the division sense. Given
1322
+ /// `let (chunks, remainder) = slice.as_chunks()`, then:
1323
+ /// - `chunks.len()` equals `slice.len() / N`,
1324
+ /// - `remainder.len()` equals `slice.len() % N`, and
1325
+ /// - `slice.len()` equals `chunks.len() * N + remainder.len()`.
1326
+ ///
1327
+ /// You can flatten the chunks back into a slice-of-`T` with [`as_flattened`].
1328
+ ///
1329
+ /// [`as_flattened`]: slice::as_flattened
1330
+ ///
1309
1331
/// # Panics
1310
1332
///
1311
- /// Panics if `N` is zero. This check will most probably get changed to a compile time
1312
- /// error before this method gets stabilized.
1333
+ /// Panics if `N` is zero.
1334
+ ///
1335
+ /// Note that this check is against a const generic parameter, not a runtime
1336
+ /// value, and thus a particular monomorphization will either always panic
1337
+ /// or it will never panic.
1313
1338
///
1314
1339
/// # Examples
1315
1340
///
@@ -1350,10 +1375,23 @@ impl<T> [T] {
1350
1375
/// starting at the end of the slice,
1351
1376
/// and a remainder slice with length strictly less than `N`.
1352
1377
///
1378
+ /// The remainder is meaningful in the division sense. Given
1379
+ /// `let (remainder, chunks) = slice.as_rchunks()`, then:
1380
+ /// - `remainder.len()` equals `slice.len() % N`,
1381
+ /// - `chunks.len()` equals `slice.len() / N`, and
1382
+ /// - `slice.len()` equals `chunks.len() * N + remainder.len()`.
1383
+ ///
1384
+ /// You can flatten the chunks back into a slice-of-`T` with [`as_flattened`].
1385
+ ///
1386
+ /// [`as_flattened`]: slice::as_flattened
1387
+ ///
1353
1388
/// # Panics
1354
1389
///
1355
- /// Panics if `N` is zero. This check will most probably get changed to a compile time
1356
- /// error before this method gets stabilized.
1390
+ /// Panics if `N` is zero.
1391
+ ///
1392
+ /// Note that this check is against a const generic parameter, not a runtime
1393
+ /// value, and thus a particular monomorphization will either always panic
1394
+ /// or it will never panic.
1357
1395
///
1358
1396
/// # Examples
1359
1397
///
@@ -1417,6 +1455,18 @@ impl<T> [T] {
1417
1455
/// Splits the slice into a slice of `N`-element arrays,
1418
1456
/// assuming that there's no remainder.
1419
1457
///
1458
+ /// This is the inverse operation to [`as_flattened_mut`].
1459
+ ///
1460
+ /// [`as_flattened_mut`]: slice::as_flattened_mut
1461
+ ///
1462
+ /// As this is `unsafe`, consider whether you could use [`as_chunks_mut`] or
1463
+ /// [`as_rchunks_mut`] instead, perhaps via something like
1464
+ /// `if let (chunks, []) = slice.as_chunks_mut()` or
1465
+ /// `let (chunks, []) = slice.as_chunks_mut() else { unreachable!() };`.
1466
+ ///
1467
+ /// [`as_chunks_mut`]: slice::as_chunks_mut
1468
+ /// [`as_rchunks_mut`]: slice::as_rchunks_mut
1469
+ ///
1420
1470
/// # Safety
1421
1471
///
1422
1472
/// This may only be called when
@@ -1463,10 +1513,23 @@ impl<T> [T] {
1463
1513
/// starting at the beginning of the slice,
1464
1514
/// and a remainder slice with length strictly less than `N`.
1465
1515
///
1516
+ /// The remainder is meaningful in the division sense. Given
1517
+ /// `let (chunks, remainder) = slice.as_chunks_mut()`, then:
1518
+ /// - `chunks.len()` equals `slice.len() / N`,
1519
+ /// - `remainder.len()` equals `slice.len() % N`, and
1520
+ /// - `slice.len()` equals `chunks.len() * N + remainder.len()`.
1521
+ ///
1522
+ /// You can flatten the chunks back into a slice-of-`T` with [`as_flattened_mut`].
1523
+ ///
1524
+ /// [`as_flattened_mut`]: slice::as_flattened_mut
1525
+ ///
1466
1526
/// # Panics
1467
1527
///
1468
- /// Panics if `N` is zero. This check will most probably get changed to a compile time
1469
- /// error before this method gets stabilized.
1528
+ /// Panics if `N` is zero.
1529
+ ///
1530
+ /// Note that this check is against a const generic parameter, not a runtime
1531
+ /// value, and thus a particular monomorphization will either always panic
1532
+ /// or it will never panic.
1470
1533
///
1471
1534
/// # Examples
1472
1535
///
@@ -1503,10 +1566,23 @@ impl<T> [T] {
1503
1566
/// starting at the end of the slice,
1504
1567
/// and a remainder slice with length strictly less than `N`.
1505
1568
///
1569
+ /// The remainder is meaningful in the division sense. Given
1570
+ /// `let (remainder, chunks) = slice.as_rchunks_mut()`, then:
1571
+ /// - `remainder.len()` equals `slice.len() % N`,
1572
+ /// - `chunks.len()` equals `slice.len() / N`, and
1573
+ /// - `slice.len()` equals `chunks.len() * N + remainder.len()`.
1574
+ ///
1575
+ /// You can flatten the chunks back into a slice-of-`T` with [`as_flattened_mut`].
1576
+ ///
1577
+ /// [`as_flattened_mut`]: slice::as_flattened_mut
1578
+ ///
1506
1579
/// # Panics
1507
1580
///
1508
- /// Panics if `N` is zero. This check will most probably get changed to a compile time
1509
- /// error before this method gets stabilized.
1581
+ /// Panics if `N` is zero.
1582
+ ///
1583
+ /// Note that this check is against a const generic parameter, not a runtime
1584
+ /// value, and thus a particular monomorphization will either always panic
1585
+ /// or it will never panic.
1510
1586
///
1511
1587
/// # Examples
1512
1588
///
@@ -4809,6 +4885,11 @@ impl<T> [MaybeUninit<T>] {
4809
4885
impl < T , const N : usize > [ [ T ; N ] ] {
4810
4886
/// Takes a `&[[T; N]]`, and flattens it to a `&[T]`.
4811
4887
///
4888
+ /// For the opposite operation, see [`as_chunks`] and [`as_rchunks`].
4889
+ ///
4890
+ /// [`as_chunks`]: slice::as_chunks
4891
+ /// [`as_rchunks`]: slice::as_rchunks
4892
+ ///
4812
4893
/// # Panics
4813
4894
///
4814
4895
/// This panics if the length of the resulting slice would overflow a `usize`.
@@ -4849,6 +4930,11 @@ impl<T, const N: usize> [[T; N]] {
4849
4930
4850
4931
/// Takes a `&mut [[T; N]]`, and flattens it to a `&mut [T]`.
4851
4932
///
4933
+ /// For the opposite operation, see [`as_chunks_mut`] and [`as_rchunks_mut`].
4934
+ ///
4935
+ /// [`as_chunks_mut`]: slice::as_chunks_mut
4936
+ /// [`as_rchunks_mut`]: slice::as_rchunks_mut
4937
+ ///
4852
4938
/// # Panics
4853
4939
///
4854
4940
/// This panics if the length of the resulting slice would overflow a `usize`.
0 commit comments