Skip to content

Add Rev delegate methods for the impl of Iterator. #57245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/libcore/iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,19 +415,25 @@ impl<I> Iterator for Rev<I> where I: DoubleEndedIterator {
type Item = <I as Iterator>::Item;

#[inline]
fn next(&mut self) -> Option<<I as Iterator>::Item> { self.iter.next_back() }
fn next(&mut self) -> Option<Self::Item> { self.iter.next_back() }
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
#[inline]
fn count(self) -> usize { self.iter.count() }
#[inline]
fn last(mut self) -> Option<Self::Item> { self.iter.next() }

#[inline]
fn nth(&mut self, n: usize) -> Option<<I as Iterator>::Item> { self.iter.nth_back(n) }
fn nth(&mut self, n: usize) -> Option<Self::Item> { self.iter.nth_back(n) }

#[inline]
fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R where
Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Ok=B>
{
self.iter.try_rfold(init, f)
}

#[inline]
fn fold<Acc, F>(self, init: Acc, f: F) -> Acc
where F: FnMut(Acc, Self::Item) -> Acc,
{
Expand All @@ -452,23 +458,26 @@ impl<I> Iterator for Rev<I> where I: DoubleEndedIterator {
#[stable(feature = "rust1", since = "1.0.0")]
impl<I> DoubleEndedIterator for Rev<I> where I: DoubleEndedIterator {
#[inline]
fn next_back(&mut self) -> Option<<I as Iterator>::Item> { self.iter.next() }
fn next_back(&mut self) -> Option<Self::Item> { self.iter.next() }

#[inline]
fn nth_back(&mut self, n: usize) -> Option<<I as Iterator>::Item> { self.iter.nth(n) }
fn nth_back(&mut self, n: usize) -> Option<Self::Item> { self.iter.nth(n) }

#[inline]
fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> R where
Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Ok=B>
{
self.iter.try_fold(init, f)
}

#[inline]
fn rfold<Acc, F>(self, init: Acc, f: F) -> Acc
where F: FnMut(Acc, Self::Item) -> Acc,
{
self.iter.fold(init, f)
}

#[inline]
fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>
where P: FnMut(&Self::Item) -> bool
{
Expand All @@ -480,10 +489,12 @@ impl<I> DoubleEndedIterator for Rev<I> where I: DoubleEndedIterator {
impl<I> ExactSizeIterator for Rev<I>
where I: ExactSizeIterator + DoubleEndedIterator
{
#[inline]
fn len(&self) -> usize {
self.iter.len()
}

#[inline]
fn is_empty(&self) -> bool {
self.iter.is_empty()
}
Expand Down