@@ -300,7 +300,7 @@ impl<T> [T] {
300
300
if let [ .., last] = self { Some ( last) } else { None }
301
301
}
302
302
303
- /// Returns a mutable pointer to the last item in the slice.
303
+ /// Returns a mutable reference to the last item in the slice.
304
304
///
305
305
/// # Examples
306
306
///
@@ -320,7 +320,9 @@ impl<T> [T] {
320
320
if let [ .., last] = self { Some ( last) } else { None }
321
321
}
322
322
323
- /// Returns the first `N` elements of the slice, or `None` if it has fewer than `N` elements.
323
+ /// Return an array reference to the first `N` items in the slice.
324
+ ///
325
+ /// If the slice is not at least `N` in length, this will return `None`.
324
326
///
325
327
/// # Examples
326
328
///
@@ -345,12 +347,13 @@ impl<T> [T] {
345
347
} else {
346
348
// SAFETY: We explicitly check for the correct number of elements,
347
349
// and do not let the reference outlive the slice.
348
- Some ( unsafe { & * ( self . as_ptr ( ) as * const [ T ; N ] ) } )
350
+ Some ( unsafe { & * ( self . as_ptr ( ) . cast :: < [ T ; N ] > ( ) ) } )
349
351
}
350
352
}
351
353
352
- /// Returns a mutable reference to the first `N` elements of the slice,
353
- /// or `None` if it has fewer than `N` elements.
354
+ /// Return a mutable array reference to the first `N` items in the slice.
355
+ ///
356
+ /// If the slice is not at least `N` in length, this will return `None`.
354
357
///
355
358
/// # Examples
356
359
///
@@ -375,12 +378,13 @@ impl<T> [T] {
375
378
// SAFETY: We explicitly check for the correct number of elements,
376
379
// do not let the reference outlive the slice,
377
380
// and require exclusive access to the entire slice to mutate the chunk.
378
- Some ( unsafe { & mut * ( self . as_mut_ptr ( ) as * mut [ T ; N ] ) } )
381
+ Some ( unsafe { & mut * ( self . as_mut_ptr ( ) . cast :: < [ T ; N ] > ( ) ) } )
379
382
}
380
383
}
381
384
382
- /// Returns the first `N` elements of the slice and the remainder,
383
- /// or `None` if it has fewer than `N` elements.
385
+ /// Return an array reference to the first `N` items in the slice and the remaining slice.
386
+ ///
387
+ /// If the slice is not at least `N` in length, this will return `None`.
384
388
///
385
389
/// # Examples
386
390
///
@@ -406,12 +410,14 @@ impl<T> [T] {
406
410
407
411
// SAFETY: We explicitly check for the correct number of elements,
408
412
// and do not let the references outlive the slice.
409
- Some ( ( unsafe { & * ( first. as_ptr ( ) as * const [ T ; N ] ) } , tail) )
413
+ Some ( ( unsafe { & * ( first. as_ptr ( ) . cast :: < [ T ; N ] > ( ) ) } , tail) )
410
414
}
411
415
}
412
416
413
- /// Returns a mutable reference to the first `N` elements of the slice and the remainder,
414
- /// or `None` if it has fewer than `N` elements.
417
+ /// Return a mutable array reference to the first `N` items in the slice and the remaining
418
+ /// slice.
419
+ ///
420
+ /// If the slice is not at least `N` in length, this will return `None`.
415
421
///
416
422
/// # Examples
417
423
///
@@ -442,12 +448,13 @@ impl<T> [T] {
442
448
// SAFETY: We explicitly check for the correct number of elements,
443
449
// do not let the reference outlive the slice,
444
450
// and enforce exclusive mutability of the chunk by the split.
445
- Some ( ( unsafe { & mut * ( first. as_mut_ptr ( ) as * mut [ T ; N ] ) } , tail) )
451
+ Some ( ( unsafe { & mut * ( first. as_mut_ptr ( ) . cast :: < [ T ; N ] > ( ) ) } , tail) )
446
452
}
447
453
}
448
454
449
- /// Returns the last `N` elements of the slice and the remainder,
450
- /// or `None` if it has fewer than `N` elements.
455
+ /// Return an array reference to the last `N` items in the slice and the remaining slice.
456
+ ///
457
+ /// If the slice is not at least `N` in length, this will return `None`.
451
458
///
452
459
/// # Examples
453
460
///
@@ -473,11 +480,14 @@ impl<T> [T] {
473
480
474
481
// SAFETY: We explicitly check for the correct number of elements,
475
482
// and do not let the references outlive the slice.
476
- Some ( ( init, unsafe { & * ( last. as_ptr ( ) as * const [ T ; N ] ) } ) )
483
+ Some ( ( init, unsafe { & * ( last. as_ptr ( ) . cast :: < [ T ; N ] > ( ) ) } ) )
477
484
}
478
485
}
479
486
480
- /// Returns the last and all the rest of the elements of the slice, or `None` if it is empty.
487
+ /// Return a mutable array reference to the last `N` items in the slice and the remaining
488
+ /// slice.
489
+ ///
490
+ /// If the slice is not at least `N` in length, this will return `None`.
481
491
///
482
492
/// # Examples
483
493
///
@@ -508,11 +518,13 @@ impl<T> [T] {
508
518
// SAFETY: We explicitly check for the correct number of elements,
509
519
// do not let the reference outlive the slice,
510
520
// and enforce exclusive mutability of the chunk by the split.
511
- Some ( ( init, unsafe { & mut * ( last. as_mut_ptr ( ) as * mut [ T ; N ] ) } ) )
521
+ Some ( ( init, unsafe { & mut * ( last. as_mut_ptr ( ) . cast :: < [ T ; N ] > ( ) ) } ) )
512
522
}
513
523
}
514
524
515
- /// Returns the last element of the slice, or `None` if it is empty.
525
+ /// Return an array reference to the last `N` items in the slice.
526
+ ///
527
+ /// If the slice is not at least `N` in length, this will return `None`.
516
528
///
517
529
/// # Examples
518
530
///
@@ -541,11 +553,13 @@ impl<T> [T] {
541
553
542
554
// SAFETY: We explicitly check for the correct number of elements,
543
555
// and do not let the references outlive the slice.
544
- Some ( unsafe { & * ( last. as_ptr ( ) as * const [ T ; N ] ) } )
556
+ Some ( unsafe { & * ( last. as_ptr ( ) . cast :: < [ T ; N ] > ( ) ) } )
545
557
}
546
558
}
547
559
548
- /// Returns a mutable pointer to the last item in the slice.
560
+ /// Return a mutable array reference to the last `N` items in the slice.
561
+ ///
562
+ /// If the slice is not at least `N` in length, this will return `None`.
549
563
///
550
564
/// # Examples
551
565
///
@@ -574,7 +588,7 @@ impl<T> [T] {
574
588
// SAFETY: We explicitly check for the correct number of elements,
575
589
// do not let the reference outlive the slice,
576
590
// and require exclusive access to the entire slice to mutate the chunk.
577
- Some ( unsafe { & mut * ( last. as_mut_ptr ( ) as * mut [ T ; N ] ) } )
591
+ Some ( unsafe { & mut * ( last. as_mut_ptr ( ) . cast :: < [ T ; N ] > ( ) ) } )
578
592
}
579
593
}
580
594
0 commit comments