Skip to content

Commit

Permalink
Use next and next_back
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Jan 6, 2018
1 parent c23d450 commit 2d83343
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/libcore/iter/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,8 @@ impl<A: Step> Iterator for ops::Range<A> {
}

#[inline]
fn max(self) -> Option<A> {
if self.start != self.end {
Some(self.end.sub_one())
} else { None }
fn max(mut self) -> Option<A> {
self.next_back()
}
}

Expand Down Expand Up @@ -376,24 +374,18 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
}

#[inline]
fn last(self) -> Option<A> {
if self.start <= self.end {
Some(self.end)
} else { None }
fn last(mut self) -> Option<A> {
self.next_back()
}

#[inline]
fn min(self) -> Option<A> {
if self.start <= self.end {
Some(self.start)
} else { None }
fn min(mut self) -> Option<A> {
self.next()
}

#[inline]
fn max(self) -> Option<A> {
if self.start <= self.end {
Some(self.end)
} else { None }
fn max(mut self) -> Option<A> {
self.next_back()
}
}

Expand Down

0 comments on commit 2d83343

Please sign in to comment.