File tree Expand file tree Collapse file tree 2 files changed +6
-3
lines changed Expand file tree Collapse file tree 2 files changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -48,11 +48,11 @@ impl<I> IteratorIndex<I> for RangeInclusive<usize>
4848where
4949 I : Iterator ,
5050{
51- type Output = Take < Skip < I > > ;
51+ type Output = Skip < Take < I > > ;
5252
5353 fn index ( self , iter : I ) -> Self :: Output {
54- iter . skip ( * self . start ( ) )
55- . take ( ( 1 + * self . end ( ) ) . saturating_sub ( * self . start ( ) ) )
54+ assert_ne ! ( * self . end ( ) , usize :: MAX ) ;
55+ iter . take ( self . end ( ) + 1 ) . skip ( * self . start ( ) )
5656 }
5757}
5858
7474 type Output = Take < I > ;
7575
7676 fn index ( self , iter : I ) -> Self :: Output {
77+ assert_ne ! ( self . end, usize :: MAX ) ;
7778 iter. take ( self . end + 1 )
7879 }
7980}
Original file line number Diff line number Diff line change @@ -511,6 +511,8 @@ pub trait Itertools: Iterator {
511511 ///
512512 /// Works similarly to [`slice::get`](https://doc.rust-lang.org/std/primitive.slice.html#method.get).
513513 ///
514+ /// **Panics** if the range includes `usize::MAX`.
515+ ///
514516 /// It's a generalisation of [`Iterator::take`] and [`Iterator::skip`],
515517 /// and uses these under the hood.
516518 /// Therefore, the resulting iterator is [`DoubleEndedIterator`]
You can’t perform that action at this time.
0 commit comments