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
+20
View File
@@ -2286,6 +2286,16 @@ fn try_fold<B, F, R>(&mut self, init: B, mut f: F) -> R
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 @@ fn fold<Acc, F>(self, mut accum: Acc, mut f: F) -> Acc
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()