Skip to content

Commit fae2a68

Browse files
committed
implement nth_back for Fuse
1 parent cc2689a commit fae2a68

File tree

1 file changed

+16
-0
lines changed
  • src/libcore/iter/adapters

1 file changed

+16
-0
lines changed

src/libcore/iter/adapters/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,17 @@ impl<I> DoubleEndedIterator for Fuse<I> where I: DoubleEndedIterator {
17891789
}
17901790
}
17911791

1792+
#[inline]
1793+
default fn nth_back(&mut self, n: usize) -> Option<<I as Iterator>::Item> {
1794+
if self.done {
1795+
None
1796+
} else {
1797+
let nth = self.iter.nth_back(n);
1798+
self.done = nth.is_none();
1799+
nth
1800+
}
1801+
}
1802+
17921803
#[inline]
17931804
default fn try_rfold<Acc, Fold, R>(&mut self, init: Acc, fold: Fold) -> R where
17941805
Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, R: Try<Ok=Acc>
@@ -1877,6 +1888,11 @@ impl<I> DoubleEndedIterator for Fuse<I>
18771888
self.iter.next_back()
18781889
}
18791890

1891+
#[inline]
1892+
fn nth_back(&mut self, n: usize) -> Option<<I as Iterator>::Item> {
1893+
self.iter.nth_back(n)
1894+
}
1895+
18801896
#[inline]
18811897
fn try_rfold<Acc, Fold, R>(&mut self, init: Acc, fold: Fold) -> R where
18821898
Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, R: Try<Ok=Acc>

0 commit comments

Comments
 (0)