We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent eaf4a6c commit 2963a6fCopy full SHA for 2963a6f
src/libcore/iter.rs
@@ -2126,12 +2126,15 @@ impl<I> Iterator for Take<I> where I: Iterator{
2126
2127
#[inline]
2128
fn nth(&mut self, n: usize) -> Option<I::Item> {
2129
- if self.n == 0 {
2130
- None
2131
- } else {
2132
- let n = cmp::min(self.n-1, n);
+ if self.n > n {
2133
self.n -= n + 1;
2134
self.iter.nth(n)
+ } else {
+ if self.n > 0 {
+ self.iter.nth(self.n - 1);
2135
+ self.n = 0;
2136
+ }
2137
+ None
2138
}
2139
2140
0 commit comments