mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Also rename ExactChunks iterator name to ChunksExact
This commit is contained in:
parent
e09e45041b
commit
068c92b2cc
@ -124,7 +124,7 @@ pub use core::slice::{from_ref, from_mut};
|
|||||||
#[stable(feature = "slice_get_slice", since = "1.28.0")]
|
#[stable(feature = "slice_get_slice", since = "1.28.0")]
|
||||||
pub use core::slice::SliceIndex;
|
pub use core::slice::SliceIndex;
|
||||||
#[unstable(feature = "chunks_exact", issue = "47115")]
|
#[unstable(feature = "chunks_exact", issue = "47115")]
|
||||||
pub use core::slice::{ExactChunks, ExactChunksMut};
|
pub use core::slice::{ChunksExact, ChunksExactMut};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Basic slice extension methods
|
// Basic slice extension methods
|
||||||
|
@ -714,12 +714,12 @@ impl<T> [T] {
|
|||||||
/// [`chunks`]: #method.chunks
|
/// [`chunks`]: #method.chunks
|
||||||
#[unstable(feature = "chunks_exact", issue = "47115")]
|
#[unstable(feature = "chunks_exact", issue = "47115")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn chunks_exact(&self, chunk_size: usize) -> ExactChunks<T> {
|
pub fn chunks_exact(&self, chunk_size: usize) -> ChunksExact<T> {
|
||||||
assert!(chunk_size != 0);
|
assert!(chunk_size != 0);
|
||||||
let rem = self.len() % chunk_size;
|
let rem = self.len() % chunk_size;
|
||||||
let len = self.len() - rem;
|
let len = self.len() - rem;
|
||||||
let (fst, snd) = self.split_at(len);
|
let (fst, snd) = self.split_at(len);
|
||||||
ExactChunks { v: fst, rem: snd, chunk_size }
|
ChunksExact { v: fst, rem: snd, chunk_size }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator over `chunk_size` elements of the slice at a time.
|
/// Returns an iterator over `chunk_size` elements of the slice at a time.
|
||||||
@ -756,12 +756,12 @@ impl<T> [T] {
|
|||||||
/// [`chunks_mut`]: #method.chunks_mut
|
/// [`chunks_mut`]: #method.chunks_mut
|
||||||
#[unstable(feature = "chunks_exact", issue = "47115")]
|
#[unstable(feature = "chunks_exact", issue = "47115")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn chunks_exact_mut(&mut self, chunk_size: usize) -> ExactChunksMut<T> {
|
pub fn chunks_exact_mut(&mut self, chunk_size: usize) -> ChunksExactMut<T> {
|
||||||
assert!(chunk_size != 0);
|
assert!(chunk_size != 0);
|
||||||
let rem = self.len() % chunk_size;
|
let rem = self.len() % chunk_size;
|
||||||
let len = self.len() - rem;
|
let len = self.len() - rem;
|
||||||
let (fst, snd) = self.split_at_mut(len);
|
let (fst, snd) = self.split_at_mut(len);
|
||||||
ExactChunksMut { v: fst, rem: snd, chunk_size }
|
ChunksExactMut { v: fst, rem: snd, chunk_size }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Divides one slice into two at an index.
|
/// Divides one slice into two at an index.
|
||||||
@ -3660,18 +3660,18 @@ unsafe impl<'a, T> TrustedRandomAccess for ChunksMut<'a, T> {
|
|||||||
/// This struct is created by the [`chunks_exact`] method on [slices].
|
/// This struct is created by the [`chunks_exact`] method on [slices].
|
||||||
///
|
///
|
||||||
/// [`chunks_exact`]: ../../std/primitive.slice.html#method.chunks_exact
|
/// [`chunks_exact`]: ../../std/primitive.slice.html#method.chunks_exact
|
||||||
/// [`remainder`]: ../../std/slice/struct.ExactChunks.html#method.remainder
|
/// [`remainder`]: ../../std/slice/struct.ChunksExact.html#method.remainder
|
||||||
/// [slices]: ../../std/primitive.slice.html
|
/// [slices]: ../../std/primitive.slice.html
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[unstable(feature = "chunks_exact", issue = "47115")]
|
#[unstable(feature = "chunks_exact", issue = "47115")]
|
||||||
pub struct ExactChunks<'a, T:'a> {
|
pub struct ChunksExact<'a, T:'a> {
|
||||||
v: &'a [T],
|
v: &'a [T],
|
||||||
rem: &'a [T],
|
rem: &'a [T],
|
||||||
chunk_size: usize
|
chunk_size: usize
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "chunks_exact", issue = "47115")]
|
#[unstable(feature = "chunks_exact", issue = "47115")]
|
||||||
impl<'a, T> ExactChunks<'a, T> {
|
impl<'a, T> ChunksExact<'a, T> {
|
||||||
/// Return the remainder of the original slice that is not going to be
|
/// Return the remainder of the original slice that is not going to be
|
||||||
/// returned by the iterator. The returned slice has at most `chunk_size-1`
|
/// returned by the iterator. The returned slice has at most `chunk_size-1`
|
||||||
/// elements.
|
/// elements.
|
||||||
@ -3682,9 +3682,9 @@ impl<'a, T> ExactChunks<'a, T> {
|
|||||||
|
|
||||||
// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
|
// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
|
||||||
#[unstable(feature = "chunks_exact", issue = "47115")]
|
#[unstable(feature = "chunks_exact", issue = "47115")]
|
||||||
impl<'a, T> Clone for ExactChunks<'a, T> {
|
impl<'a, T> Clone for ChunksExact<'a, T> {
|
||||||
fn clone(&self) -> ExactChunks<'a, T> {
|
fn clone(&self) -> ChunksExact<'a, T> {
|
||||||
ExactChunks {
|
ChunksExact {
|
||||||
v: self.v,
|
v: self.v,
|
||||||
rem: self.rem,
|
rem: self.rem,
|
||||||
chunk_size: self.chunk_size,
|
chunk_size: self.chunk_size,
|
||||||
@ -3693,7 +3693,7 @@ impl<'a, T> Clone for ExactChunks<'a, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "chunks_exact", issue = "47115")]
|
#[unstable(feature = "chunks_exact", issue = "47115")]
|
||||||
impl<'a, T> Iterator for ExactChunks<'a, T> {
|
impl<'a, T> Iterator for ChunksExact<'a, T> {
|
||||||
type Item = &'a [T];
|
type Item = &'a [T];
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -3738,7 +3738,7 @@ impl<'a, T> Iterator for ExactChunks<'a, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "chunks_exact", issue = "47115")]
|
#[unstable(feature = "chunks_exact", issue = "47115")]
|
||||||
impl<'a, T> DoubleEndedIterator for ExactChunks<'a, T> {
|
impl<'a, T> DoubleEndedIterator for ChunksExact<'a, T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next_back(&mut self) -> Option<&'a [T]> {
|
fn next_back(&mut self) -> Option<&'a [T]> {
|
||||||
if self.v.len() < self.chunk_size {
|
if self.v.len() < self.chunk_size {
|
||||||
@ -3752,20 +3752,20 @@ impl<'a, T> DoubleEndedIterator for ExactChunks<'a, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "chunks_exact", issue = "47115")]
|
#[unstable(feature = "chunks_exact", issue = "47115")]
|
||||||
impl<'a, T> ExactSizeIterator for ExactChunks<'a, T> {
|
impl<'a, T> ExactSizeIterator for ChunksExact<'a, T> {
|
||||||
fn is_empty(&self) -> bool {
|
fn is_empty(&self) -> bool {
|
||||||
self.v.is_empty()
|
self.v.is_empty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "trusted_len", issue = "37572")]
|
#[unstable(feature = "trusted_len", issue = "37572")]
|
||||||
unsafe impl<'a, T> TrustedLen for ExactChunks<'a, T> {}
|
unsafe impl<'a, T> TrustedLen for ChunksExact<'a, T> {}
|
||||||
|
|
||||||
#[unstable(feature = "chunks_exact", issue = "47115")]
|
#[unstable(feature = "chunks_exact", issue = "47115")]
|
||||||
impl<'a, T> FusedIterator for ExactChunks<'a, T> {}
|
impl<'a, T> FusedIterator for ChunksExact<'a, T> {}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
unsafe impl<'a, T> TrustedRandomAccess for ExactChunks<'a, T> {
|
unsafe impl<'a, T> TrustedRandomAccess for ChunksExact<'a, T> {
|
||||||
unsafe fn get_unchecked(&mut self, i: usize) -> &'a [T] {
|
unsafe fn get_unchecked(&mut self, i: usize) -> &'a [T] {
|
||||||
let start = i * self.chunk_size;
|
let start = i * self.chunk_size;
|
||||||
from_raw_parts(self.v.as_ptr().add(start), self.chunk_size)
|
from_raw_parts(self.v.as_ptr().add(start), self.chunk_size)
|
||||||
@ -3783,18 +3783,18 @@ unsafe impl<'a, T> TrustedRandomAccess for ExactChunks<'a, T> {
|
|||||||
/// This struct is created by the [`chunks_exact_mut`] method on [slices].
|
/// This struct is created by the [`chunks_exact_mut`] method on [slices].
|
||||||
///
|
///
|
||||||
/// [`chunks_exact_mut`]: ../../std/primitive.slice.html#method.chunks_exact_mut
|
/// [`chunks_exact_mut`]: ../../std/primitive.slice.html#method.chunks_exact_mut
|
||||||
/// [`into_remainder`]: ../../std/slice/struct.ExactChunksMut.html#method.into_remainder
|
/// [`into_remainder`]: ../../std/slice/struct.ChunksExactMut.html#method.into_remainder
|
||||||
/// [slices]: ../../std/primitive.slice.html
|
/// [slices]: ../../std/primitive.slice.html
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[unstable(feature = "chunks_exact", issue = "47115")]
|
#[unstable(feature = "chunks_exact", issue = "47115")]
|
||||||
pub struct ExactChunksMut<'a, T:'a> {
|
pub struct ChunksExactMut<'a, T:'a> {
|
||||||
v: &'a mut [T],
|
v: &'a mut [T],
|
||||||
rem: &'a mut [T],
|
rem: &'a mut [T],
|
||||||
chunk_size: usize
|
chunk_size: usize
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "chunks_exact", issue = "47115")]
|
#[unstable(feature = "chunks_exact", issue = "47115")]
|
||||||
impl<'a, T> ExactChunksMut<'a, T> {
|
impl<'a, T> ChunksExactMut<'a, T> {
|
||||||
/// Return the remainder of the original slice that is not going to be
|
/// Return the remainder of the original slice that is not going to be
|
||||||
/// returned by the iterator. The returned slice has at most `chunk_size-1`
|
/// returned by the iterator. The returned slice has at most `chunk_size-1`
|
||||||
/// elements.
|
/// elements.
|
||||||
@ -3804,7 +3804,7 @@ impl<'a, T> ExactChunksMut<'a, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "chunks_exact", issue = "47115")]
|
#[unstable(feature = "chunks_exact", issue = "47115")]
|
||||||
impl<'a, T> Iterator for ExactChunksMut<'a, T> {
|
impl<'a, T> Iterator for ChunksExactMut<'a, T> {
|
||||||
type Item = &'a mut [T];
|
type Item = &'a mut [T];
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -3851,7 +3851,7 @@ impl<'a, T> Iterator for ExactChunksMut<'a, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "chunks_exact", issue = "47115")]
|
#[unstable(feature = "chunks_exact", issue = "47115")]
|
||||||
impl<'a, T> DoubleEndedIterator for ExactChunksMut<'a, T> {
|
impl<'a, T> DoubleEndedIterator for ChunksExactMut<'a, T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next_back(&mut self) -> Option<&'a mut [T]> {
|
fn next_back(&mut self) -> Option<&'a mut [T]> {
|
||||||
if self.v.len() < self.chunk_size {
|
if self.v.len() < self.chunk_size {
|
||||||
@ -3867,20 +3867,20 @@ impl<'a, T> DoubleEndedIterator for ExactChunksMut<'a, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "chunks_exact", issue = "47115")]
|
#[unstable(feature = "chunks_exact", issue = "47115")]
|
||||||
impl<'a, T> ExactSizeIterator for ExactChunksMut<'a, T> {
|
impl<'a, T> ExactSizeIterator for ChunksExactMut<'a, T> {
|
||||||
fn is_empty(&self) -> bool {
|
fn is_empty(&self) -> bool {
|
||||||
self.v.is_empty()
|
self.v.is_empty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "trusted_len", issue = "37572")]
|
#[unstable(feature = "trusted_len", issue = "37572")]
|
||||||
unsafe impl<'a, T> TrustedLen for ExactChunksMut<'a, T> {}
|
unsafe impl<'a, T> TrustedLen for ChunksExactMut<'a, T> {}
|
||||||
|
|
||||||
#[unstable(feature = "chunks_exact", issue = "47115")]
|
#[unstable(feature = "chunks_exact", issue = "47115")]
|
||||||
impl<'a, T> FusedIterator for ExactChunksMut<'a, T> {}
|
impl<'a, T> FusedIterator for ChunksExactMut<'a, T> {}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
unsafe impl<'a, T> TrustedRandomAccess for ExactChunksMut<'a, T> {
|
unsafe impl<'a, T> TrustedRandomAccess for ChunksExactMut<'a, T> {
|
||||||
unsafe fn get_unchecked(&mut self, i: usize) -> &'a mut [T] {
|
unsafe fn get_unchecked(&mut self, i: usize) -> &'a mut [T] {
|
||||||
let start = i * self.chunk_size;
|
let start = i * self.chunk_size;
|
||||||
from_raw_parts_mut(self.v.as_mut_ptr().add(start), self.chunk_size)
|
from_raw_parts_mut(self.v.as_mut_ptr().add(start), self.chunk_size)
|
||||||
|
Loading…
Reference in New Issue
Block a user