Rollup merge of #54537 - sdroege:chunks-exact, r=alexcrichton
Rename slice::exact_chunks() to slice::chunks_exact() See https://github.com/rust-lang/rust/issues/47115#issuecomment-403090815 and https://github.com/rust-lang/rust/issues/47115#issuecomment-424053547
This commit is contained in:
commit
6a0f45b3f4
7 changed files with 101 additions and 101 deletions
|
@ -116,7 +116,7 @@
|
||||||
#![feature(unsize)]
|
#![feature(unsize)]
|
||||||
#![feature(allocator_internals)]
|
#![feature(allocator_internals)]
|
||||||
#![feature(on_unimplemented)]
|
#![feature(on_unimplemented)]
|
||||||
#![feature(exact_chunks)]
|
#![feature(chunks_exact)]
|
||||||
#![feature(rustc_const_unstable)]
|
#![feature(rustc_const_unstable)]
|
||||||
#![feature(const_vec_new)]
|
#![feature(const_vec_new)]
|
||||||
#![feature(slice_partition_dedup)]
|
#![feature(slice_partition_dedup)]
|
||||||
|
|
|
@ -123,8 +123,8 @@ pub use core::slice::{from_raw_parts, from_raw_parts_mut};
|
||||||
pub use core::slice::{from_ref, from_mut};
|
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 = "exact_chunks", 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
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#![feature(str_escape)]
|
#![feature(str_escape)]
|
||||||
#![feature(try_reserve)]
|
#![feature(try_reserve)]
|
||||||
#![feature(unboxed_closures)]
|
#![feature(unboxed_closures)]
|
||||||
#![feature(exact_chunks)]
|
#![feature(chunks_exact)]
|
||||||
#![feature(repeat_generic_slice)]
|
#![feature(repeat_generic_slice)]
|
||||||
|
|
||||||
extern crate alloc_system;
|
extern crate alloc_system;
|
||||||
|
|
|
@ -975,27 +975,27 @@ fn test_chunksator_0() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_exact_chunksator() {
|
fn test_chunks_exactator() {
|
||||||
let v = &[1, 2, 3, 4, 5];
|
let v = &[1, 2, 3, 4, 5];
|
||||||
|
|
||||||
assert_eq!(v.exact_chunks(2).len(), 2);
|
assert_eq!(v.chunks_exact(2).len(), 2);
|
||||||
|
|
||||||
let chunks: &[&[_]] = &[&[1, 2], &[3, 4]];
|
let chunks: &[&[_]] = &[&[1, 2], &[3, 4]];
|
||||||
assert_eq!(v.exact_chunks(2).collect::<Vec<_>>(), chunks);
|
assert_eq!(v.chunks_exact(2).collect::<Vec<_>>(), chunks);
|
||||||
let chunks: &[&[_]] = &[&[1, 2, 3]];
|
let chunks: &[&[_]] = &[&[1, 2, 3]];
|
||||||
assert_eq!(v.exact_chunks(3).collect::<Vec<_>>(), chunks);
|
assert_eq!(v.chunks_exact(3).collect::<Vec<_>>(), chunks);
|
||||||
let chunks: &[&[_]] = &[];
|
let chunks: &[&[_]] = &[];
|
||||||
assert_eq!(v.exact_chunks(6).collect::<Vec<_>>(), chunks);
|
assert_eq!(v.chunks_exact(6).collect::<Vec<_>>(), chunks);
|
||||||
|
|
||||||
let chunks: &[&[_]] = &[&[3, 4], &[1, 2]];
|
let chunks: &[&[_]] = &[&[3, 4], &[1, 2]];
|
||||||
assert_eq!(v.exact_chunks(2).rev().collect::<Vec<_>>(), chunks);
|
assert_eq!(v.chunks_exact(2).rev().collect::<Vec<_>>(), chunks);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_exact_chunksator_0() {
|
fn test_chunks_exactator_0() {
|
||||||
let v = &[1, 2, 3, 4];
|
let v = &[1, 2, 3, 4];
|
||||||
let _it = v.exact_chunks(0);
|
let _it = v.chunks_exact(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1235,10 +1235,10 @@ fn test_mut_chunks_0() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mut_exact_chunks() {
|
fn test_mut_chunks_exact() {
|
||||||
let mut v = [0, 1, 2, 3, 4, 5, 6];
|
let mut v = [0, 1, 2, 3, 4, 5, 6];
|
||||||
assert_eq!(v.exact_chunks_mut(2).len(), 3);
|
assert_eq!(v.chunks_exact_mut(2).len(), 3);
|
||||||
for (i, chunk) in v.exact_chunks_mut(3).enumerate() {
|
for (i, chunk) in v.chunks_exact_mut(3).enumerate() {
|
||||||
for x in chunk {
|
for x in chunk {
|
||||||
*x = i as u8;
|
*x = i as u8;
|
||||||
}
|
}
|
||||||
|
@ -1248,9 +1248,9 @@ fn test_mut_exact_chunks() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mut_exact_chunks_rev() {
|
fn test_mut_chunks_exact_rev() {
|
||||||
let mut v = [0, 1, 2, 3, 4, 5, 6];
|
let mut v = [0, 1, 2, 3, 4, 5, 6];
|
||||||
for (i, chunk) in v.exact_chunks_mut(3).rev().enumerate() {
|
for (i, chunk) in v.chunks_exact_mut(3).rev().enumerate() {
|
||||||
for x in chunk {
|
for x in chunk {
|
||||||
*x = i as u8;
|
*x = i as u8;
|
||||||
}
|
}
|
||||||
|
@ -1261,9 +1261,9 @@ fn test_mut_exact_chunks_rev() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_mut_exact_chunks_0() {
|
fn test_mut_chunks_exact_0() {
|
||||||
let mut v = [1, 2, 3, 4];
|
let mut v = [1, 2, 3, 4];
|
||||||
let _it = v.exact_chunks_mut(0);
|
let _it = v.chunks_exact_mut(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -624,7 +624,7 @@ impl<T> [T] {
|
||||||
/// not divide the length of the slice, then the last chunk will
|
/// not divide the length of the slice, then the last chunk will
|
||||||
/// not have length `chunk_size`.
|
/// not have length `chunk_size`.
|
||||||
///
|
///
|
||||||
/// See [`exact_chunks`] for a variant of this iterator that returns chunks
|
/// See [`chunks_exact`] for a variant of this iterator that returns chunks
|
||||||
/// of always exactly `chunk_size` elements.
|
/// of always exactly `chunk_size` elements.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
|
@ -642,7 +642,7 @@ impl<T> [T] {
|
||||||
/// assert!(iter.next().is_none());
|
/// assert!(iter.next().is_none());
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`exact_chunks`]: #method.exact_chunks
|
/// [`chunks_exact`]: #method.chunks_exact
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn chunks(&self, chunk_size: usize) -> Chunks<T> {
|
pub fn chunks(&self, chunk_size: usize) -> Chunks<T> {
|
||||||
|
@ -655,7 +655,7 @@ impl<T> [T] {
|
||||||
/// not divide the length of the slice, then the last chunk will not
|
/// not divide the length of the slice, then the last chunk will not
|
||||||
/// have length `chunk_size`.
|
/// have length `chunk_size`.
|
||||||
///
|
///
|
||||||
/// See [`exact_chunks_mut`] for a variant of this iterator that returns chunks
|
/// See [`chunks_exact_mut`] for a variant of this iterator that returns chunks
|
||||||
/// of always exactly `chunk_size` elements.
|
/// of always exactly `chunk_size` elements.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
|
@ -677,7 +677,7 @@ impl<T> [T] {
|
||||||
/// assert_eq!(v, &[1, 1, 2, 2, 3]);
|
/// assert_eq!(v, &[1, 1, 2, 2, 3]);
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`exact_chunks_mut`]: #method.exact_chunks_mut
|
/// [`chunks_exact_mut`]: #method.chunks_exact_mut
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<T> {
|
pub fn chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<T> {
|
||||||
|
@ -702,24 +702,24 @@ impl<T> [T] {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(exact_chunks)]
|
/// #![feature(chunks_exact)]
|
||||||
///
|
///
|
||||||
/// let slice = ['l', 'o', 'r', 'e', 'm'];
|
/// let slice = ['l', 'o', 'r', 'e', 'm'];
|
||||||
/// let mut iter = slice.exact_chunks(2);
|
/// let mut iter = slice.chunks_exact(2);
|
||||||
/// assert_eq!(iter.next().unwrap(), &['l', 'o']);
|
/// assert_eq!(iter.next().unwrap(), &['l', 'o']);
|
||||||
/// assert_eq!(iter.next().unwrap(), &['r', 'e']);
|
/// assert_eq!(iter.next().unwrap(), &['r', 'e']);
|
||||||
/// assert!(iter.next().is_none());
|
/// assert!(iter.next().is_none());
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`chunks`]: #method.chunks
|
/// [`chunks`]: #method.chunks
|
||||||
#[unstable(feature = "exact_chunks", issue = "47115")]
|
#[unstable(feature = "chunks_exact", issue = "47115")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn exact_chunks(&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.
|
||||||
|
@ -739,12 +739,12 @@ impl<T> [T] {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(exact_chunks)]
|
/// #![feature(chunks_exact)]
|
||||||
///
|
///
|
||||||
/// let v = &mut [0, 0, 0, 0, 0];
|
/// let v = &mut [0, 0, 0, 0, 0];
|
||||||
/// let mut count = 1;
|
/// let mut count = 1;
|
||||||
///
|
///
|
||||||
/// for chunk in v.exact_chunks_mut(2) {
|
/// for chunk in v.chunks_exact_mut(2) {
|
||||||
/// for elem in chunk.iter_mut() {
|
/// for elem in chunk.iter_mut() {
|
||||||
/// *elem += count;
|
/// *elem += count;
|
||||||
/// }
|
/// }
|
||||||
|
@ -754,14 +754,14 @@ impl<T> [T] {
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`chunks_mut`]: #method.chunks_mut
|
/// [`chunks_mut`]: #method.chunks_mut
|
||||||
#[unstable(feature = "exact_chunks", issue = "47115")]
|
#[unstable(feature = "chunks_exact", issue = "47115")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn exact_chunks_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.
|
||||||
|
@ -3829,21 +3829,21 @@ unsafe impl<'a, T> TrustedRandomAccess for ChunksMut<'a, T> {
|
||||||
/// up to `chunk_size-1` elements will be omitted but can be retrieved from
|
/// up to `chunk_size-1` elements will be omitted but can be retrieved from
|
||||||
/// the [`remainder`] function from the iterator.
|
/// the [`remainder`] function from the iterator.
|
||||||
///
|
///
|
||||||
/// This struct is created by the [`exact_chunks`] method on [slices].
|
/// This struct is created by the [`chunks_exact`] method on [slices].
|
||||||
///
|
///
|
||||||
/// [`exact_chunks`]: ../../std/primitive.slice.html#method.exact_chunks
|
/// [`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 = "exact_chunks", 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 = "exact_chunks", 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.
|
||||||
|
@ -3853,10 +3853,10 @@ impl<'a, T> ExactChunks<'a, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
|
// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
|
||||||
#[unstable(feature = "exact_chunks", 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,
|
||||||
|
@ -3864,8 +3864,8 @@ impl<'a, T> Clone for ExactChunks<'a, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "exact_chunks", 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]
|
||||||
|
@ -3909,8 +3909,8 @@ impl<'a, T> Iterator for ExactChunks<'a, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "exact_chunks", 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 {
|
||||||
|
@ -3923,21 +3923,21 @@ impl<'a, T> DoubleEndedIterator for ExactChunks<'a, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "exact_chunks", 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 = "exact_chunks", 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)
|
||||||
|
@ -3952,21 +3952,21 @@ unsafe impl<'a, T> TrustedRandomAccess for ExactChunks<'a, T> {
|
||||||
/// `chunk_size-1` elements will be omitted but can be retrieved from the
|
/// `chunk_size-1` elements will be omitted but can be retrieved from the
|
||||||
/// [`into_remainder`] function from the iterator.
|
/// [`into_remainder`] function from the iterator.
|
||||||
///
|
///
|
||||||
/// This struct is created by the [`exact_chunks_mut`] method on [slices].
|
/// This struct is created by the [`chunks_exact_mut`] method on [slices].
|
||||||
///
|
///
|
||||||
/// [`exact_chunks_mut`]: ../../std/primitive.slice.html#method.exact_chunks_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 = "exact_chunks", 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 = "exact_chunks", 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.
|
||||||
|
@ -3975,8 +3975,8 @@ impl<'a, T> ExactChunksMut<'a, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "exact_chunks", 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]
|
||||||
|
@ -4022,8 +4022,8 @@ impl<'a, T> Iterator for ExactChunksMut<'a, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "exact_chunks", 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 {
|
||||||
|
@ -4038,21 +4038,21 @@ impl<'a, T> DoubleEndedIterator for ExactChunksMut<'a, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "exact_chunks", 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 = "exact_chunks", 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)
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
#![feature(trusted_len)]
|
#![feature(trusted_len)]
|
||||||
#![feature(try_from)]
|
#![feature(try_from)]
|
||||||
#![feature(try_trait)]
|
#![feature(try_trait)]
|
||||||
#![feature(exact_chunks)]
|
#![feature(chunks_exact)]
|
||||||
#![feature(align_offset)]
|
#![feature(align_offset)]
|
||||||
#![feature(reverse_bits)]
|
#![feature(reverse_bits)]
|
||||||
#![feature(inner_deref)]
|
#![feature(inner_deref)]
|
||||||
|
|
|
@ -221,115 +221,115 @@ fn test_chunks_mut_zip() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_exact_chunks_count() {
|
fn test_chunks_exact_count() {
|
||||||
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
|
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
|
||||||
let c = v.exact_chunks(3);
|
let c = v.chunks_exact(3);
|
||||||
assert_eq!(c.count(), 2);
|
assert_eq!(c.count(), 2);
|
||||||
|
|
||||||
let v2: &[i32] = &[0, 1, 2, 3, 4];
|
let v2: &[i32] = &[0, 1, 2, 3, 4];
|
||||||
let c2 = v2.exact_chunks(2);
|
let c2 = v2.chunks_exact(2);
|
||||||
assert_eq!(c2.count(), 2);
|
assert_eq!(c2.count(), 2);
|
||||||
|
|
||||||
let v3: &[i32] = &[];
|
let v3: &[i32] = &[];
|
||||||
let c3 = v3.exact_chunks(2);
|
let c3 = v3.chunks_exact(2);
|
||||||
assert_eq!(c3.count(), 0);
|
assert_eq!(c3.count(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_exact_chunks_nth() {
|
fn test_chunks_exact_nth() {
|
||||||
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
|
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
|
||||||
let mut c = v.exact_chunks(2);
|
let mut c = v.chunks_exact(2);
|
||||||
assert_eq!(c.nth(1).unwrap(), &[2, 3]);
|
assert_eq!(c.nth(1).unwrap(), &[2, 3]);
|
||||||
assert_eq!(c.next().unwrap(), &[4, 5]);
|
assert_eq!(c.next().unwrap(), &[4, 5]);
|
||||||
|
|
||||||
let v2: &[i32] = &[0, 1, 2, 3, 4, 5, 6];
|
let v2: &[i32] = &[0, 1, 2, 3, 4, 5, 6];
|
||||||
let mut c2 = v2.exact_chunks(3);
|
let mut c2 = v2.chunks_exact(3);
|
||||||
assert_eq!(c2.nth(1).unwrap(), &[3, 4, 5]);
|
assert_eq!(c2.nth(1).unwrap(), &[3, 4, 5]);
|
||||||
assert_eq!(c2.next(), None);
|
assert_eq!(c2.next(), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_exact_chunks_last() {
|
fn test_chunks_exact_last() {
|
||||||
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
|
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
|
||||||
let c = v.exact_chunks(2);
|
let c = v.chunks_exact(2);
|
||||||
assert_eq!(c.last().unwrap(), &[4, 5]);
|
assert_eq!(c.last().unwrap(), &[4, 5]);
|
||||||
|
|
||||||
let v2: &[i32] = &[0, 1, 2, 3, 4];
|
let v2: &[i32] = &[0, 1, 2, 3, 4];
|
||||||
let c2 = v2.exact_chunks(2);
|
let c2 = v2.chunks_exact(2);
|
||||||
assert_eq!(c2.last().unwrap(), &[2, 3]);
|
assert_eq!(c2.last().unwrap(), &[2, 3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_exact_chunks_remainder() {
|
fn test_chunks_exact_remainder() {
|
||||||
let v: &[i32] = &[0, 1, 2, 3, 4];
|
let v: &[i32] = &[0, 1, 2, 3, 4];
|
||||||
let c = v.exact_chunks(2);
|
let c = v.chunks_exact(2);
|
||||||
assert_eq!(c.remainder(), &[4]);
|
assert_eq!(c.remainder(), &[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_exact_chunks_zip() {
|
fn test_chunks_exact_zip() {
|
||||||
let v1: &[i32] = &[0, 1, 2, 3, 4];
|
let v1: &[i32] = &[0, 1, 2, 3, 4];
|
||||||
let v2: &[i32] = &[6, 7, 8, 9, 10];
|
let v2: &[i32] = &[6, 7, 8, 9, 10];
|
||||||
|
|
||||||
let res = v1.exact_chunks(2)
|
let res = v1.chunks_exact(2)
|
||||||
.zip(v2.exact_chunks(2))
|
.zip(v2.chunks_exact(2))
|
||||||
.map(|(a, b)| a.iter().sum::<i32>() + b.iter().sum::<i32>())
|
.map(|(a, b)| a.iter().sum::<i32>() + b.iter().sum::<i32>())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
assert_eq!(res, vec![14, 22]);
|
assert_eq!(res, vec![14, 22]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_exact_chunks_mut_count() {
|
fn test_chunks_exact_mut_count() {
|
||||||
let v: &mut [i32] = &mut [0, 1, 2, 3, 4, 5];
|
let v: &mut [i32] = &mut [0, 1, 2, 3, 4, 5];
|
||||||
let c = v.exact_chunks_mut(3);
|
let c = v.chunks_exact_mut(3);
|
||||||
assert_eq!(c.count(), 2);
|
assert_eq!(c.count(), 2);
|
||||||
|
|
||||||
let v2: &mut [i32] = &mut [0, 1, 2, 3, 4];
|
let v2: &mut [i32] = &mut [0, 1, 2, 3, 4];
|
||||||
let c2 = v2.exact_chunks_mut(2);
|
let c2 = v2.chunks_exact_mut(2);
|
||||||
assert_eq!(c2.count(), 2);
|
assert_eq!(c2.count(), 2);
|
||||||
|
|
||||||
let v3: &mut [i32] = &mut [];
|
let v3: &mut [i32] = &mut [];
|
||||||
let c3 = v3.exact_chunks_mut(2);
|
let c3 = v3.chunks_exact_mut(2);
|
||||||
assert_eq!(c3.count(), 0);
|
assert_eq!(c3.count(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_exact_chunks_mut_nth() {
|
fn test_chunks_exact_mut_nth() {
|
||||||
let v: &mut [i32] = &mut [0, 1, 2, 3, 4, 5];
|
let v: &mut [i32] = &mut [0, 1, 2, 3, 4, 5];
|
||||||
let mut c = v.exact_chunks_mut(2);
|
let mut c = v.chunks_exact_mut(2);
|
||||||
assert_eq!(c.nth(1).unwrap(), &[2, 3]);
|
assert_eq!(c.nth(1).unwrap(), &[2, 3]);
|
||||||
assert_eq!(c.next().unwrap(), &[4, 5]);
|
assert_eq!(c.next().unwrap(), &[4, 5]);
|
||||||
|
|
||||||
let v2: &mut [i32] = &mut [0, 1, 2, 3, 4, 5, 6];
|
let v2: &mut [i32] = &mut [0, 1, 2, 3, 4, 5, 6];
|
||||||
let mut c2 = v2.exact_chunks_mut(3);
|
let mut c2 = v2.chunks_exact_mut(3);
|
||||||
assert_eq!(c2.nth(1).unwrap(), &[3, 4, 5]);
|
assert_eq!(c2.nth(1).unwrap(), &[3, 4, 5]);
|
||||||
assert_eq!(c2.next(), None);
|
assert_eq!(c2.next(), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_exact_chunks_mut_last() {
|
fn test_chunks_exact_mut_last() {
|
||||||
let v: &mut [i32] = &mut [0, 1, 2, 3, 4, 5];
|
let v: &mut [i32] = &mut [0, 1, 2, 3, 4, 5];
|
||||||
let c = v.exact_chunks_mut(2);
|
let c = v.chunks_exact_mut(2);
|
||||||
assert_eq!(c.last().unwrap(), &[4, 5]);
|
assert_eq!(c.last().unwrap(), &[4, 5]);
|
||||||
|
|
||||||
let v2: &mut [i32] = &mut [0, 1, 2, 3, 4];
|
let v2: &mut [i32] = &mut [0, 1, 2, 3, 4];
|
||||||
let c2 = v2.exact_chunks_mut(2);
|
let c2 = v2.chunks_exact_mut(2);
|
||||||
assert_eq!(c2.last().unwrap(), &[2, 3]);
|
assert_eq!(c2.last().unwrap(), &[2, 3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_exact_chunks_mut_remainder() {
|
fn test_chunks_exact_mut_remainder() {
|
||||||
let v: &mut [i32] = &mut [0, 1, 2, 3, 4];
|
let v: &mut [i32] = &mut [0, 1, 2, 3, 4];
|
||||||
let c = v.exact_chunks_mut(2);
|
let c = v.chunks_exact_mut(2);
|
||||||
assert_eq!(c.into_remainder(), &[4]);
|
assert_eq!(c.into_remainder(), &[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_exact_chunks_mut_zip() {
|
fn test_chunks_exact_mut_zip() {
|
||||||
let v1: &mut [i32] = &mut [0, 1, 2, 3, 4];
|
let v1: &mut [i32] = &mut [0, 1, 2, 3, 4];
|
||||||
let v2: &[i32] = &[6, 7, 8, 9, 10];
|
let v2: &[i32] = &[6, 7, 8, 9, 10];
|
||||||
|
|
||||||
for (a, b) in v1.exact_chunks_mut(2).zip(v2.exact_chunks(2)) {
|
for (a, b) in v1.chunks_exact_mut(2).zip(v2.chunks_exact(2)) {
|
||||||
let sum = b.iter().sum::<i32>();
|
let sum = b.iter().sum::<i32>();
|
||||||
for v in a {
|
for v in a {
|
||||||
*v += sum;
|
*v += sum;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue