From e09e45041b5cab9d849b554824c6683de6372e41 Mon Sep 17 00:00:00 2001 From: Sebastian Dröge Date: Mon, 24 Sep 2018 22:43:06 +0300 Subject: 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 --- src/liballoc/lib.rs | 2 +- src/liballoc/slice.rs | 2 +- src/liballoc/tests/lib.rs | 2 +- src/liballoc/tests/slice.rs | 30 +++++++++++++++--------------- 4 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 089480c06d2..63ab5043ec5 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -116,7 +116,7 @@ #![feature(unsize)] #![feature(allocator_internals)] #![feature(on_unimplemented)] -#![feature(exact_chunks)] +#![feature(chunks_exact)] #![feature(rustc_const_unstable)] #![feature(const_vec_new)] #![feature(maybe_uninit)] diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index 6c0b1c33a1f..22c15fd8a51 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -123,7 +123,7 @@ pub use core::slice::{from_raw_parts, from_raw_parts_mut}; pub use core::slice::{from_ref, from_mut}; #[stable(feature = "slice_get_slice", since = "1.28.0")] pub use core::slice::SliceIndex; -#[unstable(feature = "exact_chunks", issue = "47115")] +#[unstable(feature = "chunks_exact", issue = "47115")] pub use core::slice::{ExactChunks, ExactChunksMut}; //////////////////////////////////////////////////////////////////////////////// diff --git a/src/liballoc/tests/lib.rs b/src/liballoc/tests/lib.rs index 710c659ac53..6ff39227555 100644 --- a/src/liballoc/tests/lib.rs +++ b/src/liballoc/tests/lib.rs @@ -20,7 +20,7 @@ #![feature(str_escape)] #![feature(try_reserve)] #![feature(unboxed_closures)] -#![feature(exact_chunks)] +#![feature(chunks_exact)] #![feature(repeat_generic_slice)] extern crate alloc_system; diff --git a/src/liballoc/tests/slice.rs b/src/liballoc/tests/slice.rs index f33bf64d40b..c214c59618d 100644 --- a/src/liballoc/tests/slice.rs +++ b/src/liballoc/tests/slice.rs @@ -975,27 +975,27 @@ fn test_chunksator_0() { } #[test] -fn test_exact_chunksator() { +fn test_chunks_exactator() { 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]]; - assert_eq!(v.exact_chunks(2).collect::>(), chunks); + assert_eq!(v.chunks_exact(2).collect::>(), chunks); let chunks: &[&[_]] = &[&[1, 2, 3]]; - assert_eq!(v.exact_chunks(3).collect::>(), chunks); + assert_eq!(v.chunks_exact(3).collect::>(), chunks); let chunks: &[&[_]] = &[]; - assert_eq!(v.exact_chunks(6).collect::>(), chunks); + assert_eq!(v.chunks_exact(6).collect::>(), chunks); let chunks: &[&[_]] = &[&[3, 4], &[1, 2]]; - assert_eq!(v.exact_chunks(2).rev().collect::>(), chunks); + assert_eq!(v.chunks_exact(2).rev().collect::>(), chunks); } #[test] #[should_panic] -fn test_exact_chunksator_0() { +fn test_chunks_exactator_0() { let v = &[1, 2, 3, 4]; - let _it = v.exact_chunks(0); + let _it = v.chunks_exact(0); } #[test] @@ -1235,10 +1235,10 @@ fn test_mut_chunks_0() { } #[test] -fn test_mut_exact_chunks() { +fn test_mut_chunks_exact() { let mut v = [0, 1, 2, 3, 4, 5, 6]; - assert_eq!(v.exact_chunks_mut(2).len(), 3); - for (i, chunk) in v.exact_chunks_mut(3).enumerate() { + assert_eq!(v.chunks_exact_mut(2).len(), 3); + for (i, chunk) in v.chunks_exact_mut(3).enumerate() { for x in chunk { *x = i as u8; } @@ -1248,9 +1248,9 @@ fn test_mut_exact_chunks() { } #[test] -fn test_mut_exact_chunks_rev() { +fn test_mut_chunks_exact_rev() { 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 { *x = i as u8; } @@ -1261,9 +1261,9 @@ fn test_mut_exact_chunks_rev() { #[test] #[should_panic] -fn test_mut_exact_chunks_0() { +fn test_mut_chunks_exact_0() { let mut v = [1, 2, 3, 4]; - let _it = v.exact_chunks_mut(0); + let _it = v.chunks_exact_mut(0); } #[test] -- cgit 1.4.1-3-g733a5 From 068c92b2cc0620d18eee1066cd3460f37c9ed9f3 Mon Sep 17 00:00:00 2001 From: Sebastian Dröge Date: Tue, 25 Sep 2018 08:56:48 +0300 Subject: Also rename ExactChunks iterator name to ChunksExact --- src/liballoc/slice.rs | 2 +- src/libcore/slice/mod.rs | 50 ++++++++++++++++++++++++------------------------ 2 files changed, 26 insertions(+), 26 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index 22c15fd8a51..33d28bef2d7 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -124,7 +124,7 @@ pub use core::slice::{from_ref, from_mut}; #[stable(feature = "slice_get_slice", since = "1.28.0")] pub use core::slice::SliceIndex; #[unstable(feature = "chunks_exact", issue = "47115")] -pub use core::slice::{ExactChunks, ExactChunksMut}; +pub use core::slice::{ChunksExact, ChunksExactMut}; //////////////////////////////////////////////////////////////////////////////// // Basic slice extension methods diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 68cefe4b6a8..b3f90e3eee8 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -714,12 +714,12 @@ impl [T] { /// [`chunks`]: #method.chunks #[unstable(feature = "chunks_exact", issue = "47115")] #[inline] - pub fn chunks_exact(&self, chunk_size: usize) -> ExactChunks { + pub fn chunks_exact(&self, chunk_size: usize) -> ChunksExact { assert!(chunk_size != 0); let rem = self.len() % chunk_size; let len = self.len() - rem; 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. @@ -756,12 +756,12 @@ impl [T] { /// [`chunks_mut`]: #method.chunks_mut #[unstable(feature = "chunks_exact", issue = "47115")] #[inline] - pub fn chunks_exact_mut(&mut self, chunk_size: usize) -> ExactChunksMut { + pub fn chunks_exact_mut(&mut self, chunk_size: usize) -> ChunksExactMut { assert!(chunk_size != 0); let rem = self.len() % chunk_size; let len = self.len() - rem; 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. @@ -3660,18 +3660,18 @@ unsafe impl<'a, T> TrustedRandomAccess for ChunksMut<'a, T> { /// This struct is created by the [`chunks_exact`] method on [slices]. /// /// [`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 #[derive(Debug)] #[unstable(feature = "chunks_exact", issue = "47115")] -pub struct ExactChunks<'a, T:'a> { +pub struct ChunksExact<'a, T:'a> { v: &'a [T], rem: &'a [T], chunk_size: usize } #[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 /// returned by the iterator. The returned slice has at most `chunk_size-1` /// elements. @@ -3682,9 +3682,9 @@ impl<'a, T> ExactChunks<'a, T> { // FIXME(#26925) Remove in favor of `#[derive(Clone)]` #[unstable(feature = "chunks_exact", issue = "47115")] -impl<'a, T> Clone for ExactChunks<'a, T> { - fn clone(&self) -> ExactChunks<'a, T> { - ExactChunks { +impl<'a, T> Clone for ChunksExact<'a, T> { + fn clone(&self) -> ChunksExact<'a, T> { + ChunksExact { v: self.v, rem: self.rem, chunk_size: self.chunk_size, @@ -3693,7 +3693,7 @@ impl<'a, T> Clone for ExactChunks<'a, T> { } #[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]; #[inline] @@ -3738,7 +3738,7 @@ impl<'a, T> Iterator for ExactChunks<'a, T> { } #[unstable(feature = "chunks_exact", issue = "47115")] -impl<'a, T> DoubleEndedIterator for ExactChunks<'a, T> { +impl<'a, T> DoubleEndedIterator for ChunksExact<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a [T]> { 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")] -impl<'a, T> ExactSizeIterator for ExactChunks<'a, T> { +impl<'a, T> ExactSizeIterator for ChunksExact<'a, T> { fn is_empty(&self) -> bool { self.v.is_empty() } } #[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")] -impl<'a, T> FusedIterator for ExactChunks<'a, T> {} +impl<'a, T> FusedIterator for ChunksExact<'a, T> {} #[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] { let start = i * 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]. /// /// [`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 #[derive(Debug)] #[unstable(feature = "chunks_exact", issue = "47115")] -pub struct ExactChunksMut<'a, T:'a> { +pub struct ChunksExactMut<'a, T:'a> { v: &'a mut [T], rem: &'a mut [T], chunk_size: usize } #[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 /// returned by the iterator. The returned slice has at most `chunk_size-1` /// elements. @@ -3804,7 +3804,7 @@ impl<'a, T> ExactChunksMut<'a, T> { } #[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]; #[inline] @@ -3851,7 +3851,7 @@ impl<'a, T> Iterator for ExactChunksMut<'a, T> { } #[unstable(feature = "chunks_exact", issue = "47115")] -impl<'a, T> DoubleEndedIterator for ExactChunksMut<'a, T> { +impl<'a, T> DoubleEndedIterator for ChunksExactMut<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a mut [T]> { 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")] -impl<'a, T> ExactSizeIterator for ExactChunksMut<'a, T> { +impl<'a, T> ExactSizeIterator for ChunksExactMut<'a, T> { fn is_empty(&self) -> bool { self.v.is_empty() } } #[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")] -impl<'a, T> FusedIterator for ExactChunksMut<'a, T> {} +impl<'a, T> FusedIterator for ChunksExactMut<'a, T> {} #[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] { let start = i * self.chunk_size; from_raw_parts_mut(self.v.as_mut_ptr().add(start), self.chunk_size) -- cgit 1.4.1-3-g733a5