Skip to content

Commit d21eeb1

Browse files
committed
Override nth for VecDeque Iter and IterMut
1 parent 10671f1 commit d21eeb1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/liballoc/collections/vec_deque.rs

+20
Original file line numberDiff line numberDiff line change
@@ -2286,6 +2286,16 @@ impl<'a, T> Iterator for Iter<'a, T> {
22862286
final_res
22872287
}
22882288

2289+
fn nth(&mut self, n: usize) -> Option<Self::Item> {
2290+
if n >= count(self.tail, self.head, self.ring.len()) {
2291+
self.tail = self.head;
2292+
None
2293+
} else {
2294+
self.tail = wrap_index(self.tail.wrapping_add(n), self.ring.len());
2295+
self.next()
2296+
}
2297+
}
2298+
22892299
#[inline]
22902300
fn last(mut self) -> Option<&'a T> {
22912301
self.next_back()
@@ -2404,6 +2414,16 @@ impl<'a, T> Iterator for IterMut<'a, T> {
24042414
back.iter_mut().fold(accum, &mut f)
24052415
}
24062416

2417+
fn nth(&mut self, n: usize) -> Option<Self::Item> {
2418+
if n >= count(self.tail, self.head, self.ring.len()) {
2419+
self.tail = self.head;
2420+
None
2421+
} else {
2422+
self.tail = wrap_index(self.tail.wrapping_add(n), self.ring.len());
2423+
self.next()
2424+
}
2425+
}
2426+
24072427
#[inline]
24082428
fn last(mut self) -> Option<&'a mut T> {
24092429
self.next_back()

0 commit comments

Comments
 (0)