mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-08 01:28:18 +03:00
constify slice_as_chunks (unstable)
Tracking issue: 74985 Nothing complicated required; just adding `const` to the declarations.
This commit is contained in:
@@ -995,7 +995,7 @@ pub fn chunks_exact_mut(&mut self, chunk_size: usize) -> ChunksExactMut<'_, T> {
|
||||
#[unstable(feature = "slice_as_chunks", issue = "74985")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub unsafe fn as_chunks_unchecked<const N: usize>(&self) -> &[[T; N]] {
|
||||
pub const unsafe fn as_chunks_unchecked<const N: usize>(&self) -> &[[T; N]] {
|
||||
let this = self;
|
||||
// SAFETY: Caller must guarantee that `N` is nonzero and exactly divides the slice length
|
||||
let new_len = unsafe {
|
||||
@@ -1043,7 +1043,7 @@ pub fn chunks_exact_mut(&mut self, chunk_size: usize) -> ChunksExactMut<'_, T> {
|
||||
#[inline]
|
||||
#[track_caller]
|
||||
#[must_use]
|
||||
pub fn as_chunks<const N: usize>(&self) -> (&[[T; N]], &[T]) {
|
||||
pub const fn as_chunks<const N: usize>(&self) -> (&[[T; N]], &[T]) {
|
||||
assert!(N != 0, "chunk size must be non-zero");
|
||||
let len = self.len() / N;
|
||||
let (multiple_of_n, remainder) = self.split_at(len * N);
|
||||
@@ -1075,7 +1075,7 @@ pub fn chunks_exact_mut(&mut self, chunk_size: usize) -> ChunksExactMut<'_, T> {
|
||||
#[inline]
|
||||
#[track_caller]
|
||||
#[must_use]
|
||||
pub fn as_rchunks<const N: usize>(&self) -> (&[T], &[[T; N]]) {
|
||||
pub const fn as_rchunks<const N: usize>(&self) -> (&[T], &[[T; N]]) {
|
||||
assert!(N != 0, "chunk size must be non-zero");
|
||||
let len = self.len() / N;
|
||||
let (remainder, multiple_of_n) = self.split_at(self.len() - len * N);
|
||||
@@ -1152,7 +1152,7 @@ pub fn array_chunks<const N: usize>(&self) -> ArrayChunks<'_, T, N> {
|
||||
#[unstable(feature = "slice_as_chunks", issue = "74985")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub unsafe fn as_chunks_unchecked_mut<const N: usize>(&mut self) -> &mut [[T; N]] {
|
||||
pub const unsafe fn as_chunks_unchecked_mut<const N: usize>(&mut self) -> &mut [[T; N]] {
|
||||
let this = &*self;
|
||||
// SAFETY: Caller must guarantee that `N` is nonzero and exactly divides the slice length
|
||||
let new_len = unsafe {
|
||||
@@ -1195,7 +1195,7 @@ pub fn array_chunks<const N: usize>(&self) -> ArrayChunks<'_, T, N> {
|
||||
#[inline]
|
||||
#[track_caller]
|
||||
#[must_use]
|
||||
pub fn as_chunks_mut<const N: usize>(&mut self) -> (&mut [[T; N]], &mut [T]) {
|
||||
pub const fn as_chunks_mut<const N: usize>(&mut self) -> (&mut [[T; N]], &mut [T]) {
|
||||
assert!(N != 0, "chunk size must be non-zero");
|
||||
let len = self.len() / N;
|
||||
let (multiple_of_n, remainder) = self.split_at_mut(len * N);
|
||||
@@ -1233,7 +1233,7 @@ pub fn array_chunks<const N: usize>(&self) -> ArrayChunks<'_, T, N> {
|
||||
#[inline]
|
||||
#[track_caller]
|
||||
#[must_use]
|
||||
pub fn as_rchunks_mut<const N: usize>(&mut self) -> (&mut [T], &mut [[T; N]]) {
|
||||
pub const fn as_rchunks_mut<const N: usize>(&mut self) -> (&mut [T], &mut [[T; N]]) {
|
||||
assert!(N != 0, "chunk size must be non-zero");
|
||||
let len = self.len() / N;
|
||||
let (remainder, multiple_of_n) = self.split_at_mut(self.len() - len * N);
|
||||
|
||||
Reference in New Issue
Block a user