diff options
| author | @amit.chandra <@amit.chandra> | 2019-04-26 19:53:18 +0530 |
|---|---|---|
| committer | wizAmit <amitforfriends_dns@yahoo.com> | 2019-05-22 22:02:17 +0530 |
| commit | 29a103daa92bb3607fd4cd34169d4ff6170987fa (patch) | |
| tree | f9d4957d976de22630ffa38527d018a429bb72ef /src/libcore | |
| parent | 2080b86566358dad8cb8c967e321a172a69c49f7 (diff) | |
| download | rust-29a103daa92bb3607fd4cd34169d4ff6170987fa.tar.gz rust-29a103daa92bb3607fd4cd34169d4ff6170987fa.zip | |
wip nth_back on chunks
Signed-off-by: wizAmit <amitforfriends_dns@yahoo.com>
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/slice/mod.rs | 17 | ||||
| -rw-r--r-- | src/libcore/tests/slice.rs | 19 |
2 files changed, 0 insertions, 36 deletions
diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index b138ae3449f..d06d107d32a 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -4178,23 +4178,6 @@ impl<'a, T> DoubleEndedIterator for Chunks<'a, T> { Some(snd) } } - - #[inline] - fn nth_back(&mut self, n: usize) -> Option<Self::Item> { - let (end, overflow) = self.v.len().overflowing_sub(n * self.chunk_size); - if overflow { - self.v = &mut []; - None - } else { - let start = match end.checked_sub(self.chunk_size) { - Some(res) => cmp::min(self.v.len(), res), - None => 0, - }; - let nth_back = &self.v[start..end]; - self.v = &self.v[..start]; - Some(nth_back) - } - } } #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs index edea405fad7..1cba4b38382 100644 --- a/src/libcore/tests/slice.rs +++ b/src/libcore/tests/slice.rs @@ -134,25 +134,6 @@ fn test_chunks_nth() { assert_eq!(c2.next(), None); } -#[test] -fn test_chunks_nth_back() { - let v: &[i32] = &[0, 1, 2, 3, 4, 5]; - let mut c = v.chunks(2); - assert_eq!(c.nth_back(1).unwrap(), &[2, 3]); - assert_eq!(c.next().unwrap(), &[0, 1]); - assert_eq!(c.next(), None); - - let v2: &[i32] = &[0, 1, 2, 3, 4]; - let mut c2 = v2.chunks(3); - assert_eq!(c2.nth_back(1).unwrap(), &[0, 1]); - assert_eq!(c2.next(), None); - assert_eq!(c2.next_back(), None); - - let v3: &[i32] = &[0, 1, 2, 3, 4]; - let mut c3 = v3.chunks(10); - assert_eq!(c3.nth_back(0).unwrap(), &[0, 1, 2, 3, 4]); - assert_eq!(c3.next(), None); -} #[test] fn test_chunks_last() { |
