Skip to content

Commit 29a103d

Browse files
@amit.chandrawizAmit
@amit.chandra
authored andcommitted
wip nth_back on chunks
Signed-off-by: wizAmit <amitforfriends_dns@yahoo.com>
1 parent 2080b86 commit 29a103d

File tree

2 files changed

+0
-36
lines changed

2 files changed

+0
-36
lines changed

src/libcore/slice/mod.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4178,23 +4178,6 @@ impl<'a, T> DoubleEndedIterator for Chunks<'a, T> {
41784178
Some(snd)
41794179
}
41804180
}
4181-
4182-
#[inline]
4183-
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
4184-
let (end, overflow) = self.v.len().overflowing_sub(n * self.chunk_size);
4185-
if overflow {
4186-
self.v = &mut [];
4187-
None
4188-
} else {
4189-
let start = match end.checked_sub(self.chunk_size) {
4190-
Some(res) => cmp::min(self.v.len(), res),
4191-
None => 0,
4192-
};
4193-
let nth_back = &self.v[start..end];
4194-
self.v = &self.v[..start];
4195-
Some(nth_back)
4196-
}
4197-
}
41984181
}
41994182

42004183
#[stable(feature = "rust1", since = "1.0.0")]

src/libcore/tests/slice.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -134,25 +134,6 @@ fn test_chunks_nth() {
134134
assert_eq!(c2.next(), None);
135135
}
136136

137-
#[test]
138-
fn test_chunks_nth_back() {
139-
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
140-
let mut c = v.chunks(2);
141-
assert_eq!(c.nth_back(1).unwrap(), &[2, 3]);
142-
assert_eq!(c.next().unwrap(), &[0, 1]);
143-
assert_eq!(c.next(), None);
144-
145-
let v2: &[i32] = &[0, 1, 2, 3, 4];
146-
let mut c2 = v2.chunks(3);
147-
assert_eq!(c2.nth_back(1).unwrap(), &[0, 1]);
148-
assert_eq!(c2.next(), None);
149-
assert_eq!(c2.next_back(), None);
150-
151-
let v3: &[i32] = &[0, 1, 2, 3, 4];
152-
let mut c3 = v3.chunks(10);
153-
assert_eq!(c3.nth_back(0).unwrap(), &[0, 1, 2, 3, 4]);
154-
assert_eq!(c3.next(), None);
155-
}
156137

157138
#[test]
158139
fn test_chunks_last() {

0 commit comments

Comments
 (0)