Skip to content

Commit 77a3de3

Browse files
committed
Implement size_hint() on RangeInclusive
1 parent 063a005 commit 77a3de3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/libstd/iterator.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,21 @@ impl<A: Add<A, A> + Ord + Clone> Iterator<A> for RangeInclusive<A> {
15921592
}
15931593
}
15941594
}
1595+
1596+
#[inline]
1597+
fn size_hint(&self) -> (uint, Option<uint>) {
1598+
let (lo, hi) = self.range.size_hint();
1599+
if self.done {
1600+
(lo, hi)
1601+
} else {
1602+
let lo = lo.saturating_add(1);
1603+
let hi = match hi {
1604+
Some(x) => x.checked_add(&1),
1605+
None => None
1606+
};
1607+
(lo, hi)
1608+
}
1609+
}
15951610
}
15961611

15971612
impl<A: Sub<A, A> + Integer + Ord + Clone> DoubleEndedIterator<A> for RangeInclusive<A> {

0 commit comments

Comments
 (0)