Override nth for VecDeque Iter and IterMut
This commit is contained in:
parent
10671f10c3
commit
d21eeb110c
1 changed files with 20 additions and 0 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue