1
Fork 0

Override nth for VecDeque Iter and IterMut

This commit is contained in:
Charles Gleason 2019-10-04 19:07:13 -04:00
parent 10671f10c3
commit d21eeb110c

View file

@ -2286,6 +2286,16 @@ impl<'a, T> Iterator for Iter<'a, T> {
final_res
}
fn nth(&mut self, n: usize) -> Option<Self::Item> {
if n >= count(self.tail, self.head, self.ring.len()) {
self.tail = self.head;
None
} else {
self.tail = wrap_index(self.tail.wrapping_add(n), self.ring.len());
self.next()
}
}
#[inline]
fn last(mut self) -> Option<&'a T> {
self.next_back()
@ -2404,6 +2414,16 @@ impl<'a, T> Iterator for IterMut<'a, T> {
back.iter_mut().fold(accum, &mut f)
}
fn nth(&mut self, n: usize) -> Option<Self::Item> {
if n >= count(self.tail, self.head, self.ring.len()) {
self.tail = self.head;
None
} else {
self.tail = wrap_index(self.tail.wrapping_add(n), self.ring.len());
self.next()
}
}
#[inline]
fn last(mut self) -> Option<&'a mut T> {
self.next_back()