| 1 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::{Skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/skip/Skip#, Takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/take/Take#}; |
| 2 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::{Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#, RangeFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#, RangeFullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#, RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#, RangeTorust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#, RangeToInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeToInclusive#}; |
| 3 | |
| 4 | #[cfg(doc)] |
| 5 | use craterust-analyzer cargo itertools 0.14.0 crate/::Itertoolsrust-analyzer cargo itertools 0.14.0 Itertools#; |
| 6 | |
| 7 | mod private_iter_indexrust-analyzer cargo itertools 0.14.0 iter_index/private_iter_index/ { |
| 8 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/; |
| 9 | |
| 10 | pub trait Sealedrust-analyzer cargo itertools 0.14.0 iter_index/private_iter_index/Sealed# {} |
| 11 | |
| 12 | impl Sealedrust-analyzer cargo itertools 0.14.0 iter_index/private_iter_index/Sealed# for opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize> {} |
| 13 | impl Sealedrust-analyzer cargo itertools 0.14.0 iter_index/private_iter_index/Sealed# for opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#<usize> {} |
| 14 | impl Sealedrust-analyzer cargo itertools 0.14.0 iter_index/private_iter_index/Sealed# for opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::RangeTorust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#<usize> {} |
| 15 | impl Sealedrust-analyzer cargo itertools 0.14.0 iter_index/private_iter_index/Sealed# for opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::RangeToInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeToInclusive#<usize> {} |
| 16 | impl Sealedrust-analyzer cargo itertools 0.14.0 iter_index/private_iter_index/Sealed# for opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::RangeFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#<usize> {} |
| 17 | impl Sealedrust-analyzer cargo itertools 0.14.0 iter_index/private_iter_index/Sealed# for opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::RangeFullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull# {} |
| 18 | } |
| 19 | |
| 20 | /// Used by [`Itertools::get`] to know which iterator |
| 21 | /// to turn different ranges into. |
| 22 | pub trait IteratorIndexrust-analyzer cargo itertools 0.14.0 iter_index/IteratorIndex#<I>: private_iter_indexrust-analyzer cargo itertools 0.14.0 iter_index/private_iter_index/::Sealedrust-analyzer cargo itertools 0.14.0 iter_index/private_iter_index/Sealed# |
| 23 | where |
| 24 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, |
| 25 | { |
| 26 | /// The type returned for this type of index. |
| 27 | type Outputrust-analyzer cargo itertools 0.14.0 iter_index/IteratorIndex#Output#: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#>; |
| 28 | |
| 29 | /// Returns an adapted iterator for the current index. |
| 30 | /// |
| 31 | /// Prefer calling [`Itertools::get`] instead |
| 32 | /// of calling this directly. |
| 33 | fn indexrust-analyzer cargo itertools 0.14.0 iter_index/IteratorIndex#index().(self, from: I) -> Self::Outputrust-analyzer cargo itertools 0.14.0 iter_index/IteratorIndex#Output#; |
| 34 | } |
| 35 | |
| 36 | impl<I> IteratorIndexrust-analyzer cargo itertools 0.14.0 iter_index/IteratorIndex#<I> for Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize> |
| 37 | where |
| 38 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, |
| 39 | { |
| 40 | type Outputrust-analyzer cargo itertools 0.14.0 iter_index/impl#[`Range<usize>`][`IteratorIndex<I>`]Output# = Skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/skip/Skip#<Takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/take/Take#<I>>; |
| 41 | |
| 42 | fn indexrust-analyzer cargo itertools 0.14.0 iter_index/impl#[`Range<usize>`][`IteratorIndex<I>`]index().(self, iter: I) -> Selfrust-analyzer cargo itertools 0.14.0 iter_index/impl#[`Range<usize>`][`IteratorIndex<I>`]::Outputrust-analyzer cargo itertools 0.14.0 iter_index/IteratorIndex#Output# { |
| 43 | iter.takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(self.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end.).skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(self.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start.) |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | impl<I> IteratorIndexrust-analyzer cargo itertools 0.14.0 iter_index/IteratorIndex#<I> for RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#<usize> |
| 48 | where |
| 49 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, |
| 50 | { |
| 51 | type Outputrust-analyzer cargo itertools 0.14.0 iter_index/impl#[`RangeInclusive<usize>`][`IteratorIndex<I>`]Output# = Takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/take/Take#<Skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/skip/Skip#<I>>; |
| 52 | |
| 53 | fn indexrust-analyzer cargo itertools 0.14.0 iter_index/impl#[`RangeInclusive<usize>`][`IteratorIndex<I>`]index().(self, iter: I) -> Selfrust-analyzer cargo itertools 0.14.0 iter_index/impl#[`RangeInclusive<usize>`][`IteratorIndex<I>`]::Outputrust-analyzer cargo itertools 0.14.0 iter_index/IteratorIndex#Output# { |
| 54 | // end - start + 1 without overflowing if possible |
| 55 | let length = if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]end().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().usize::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]MAX. { |
| 56 | assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_ne!!(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]start().(), 0); |
| 57 | self.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]end().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&usize`][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&usize`][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&usize`][`Sub<Self>`]sub().self.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]start().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1 |
| 58 | } else { |
| 59 | (self.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]end().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&usize`][`Add<usize>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&usize`][`Add<usize>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&usize`][`Add<usize>`]add().1).saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_sub().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]start().()) |
| 60 | }; |
| 61 | iter.skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]start().()).takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(length) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | impl<I> IteratorIndexrust-analyzer cargo itertools 0.14.0 iter_index/IteratorIndex#<I> for RangeTorust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#<usize> |
| 66 | where |
| 67 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, |
| 68 | { |
| 69 | type Outputrust-analyzer cargo itertools 0.14.0 iter_index/impl#[`RangeTo<usize>`][`IteratorIndex<I>`]Output# = Takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/take/Take#<I>; |
| 70 | |
| 71 | fn indexrust-analyzer cargo itertools 0.14.0 iter_index/impl#[`RangeTo<usize>`][`IteratorIndex<I>`]index().(self, iter: I) -> Selfrust-analyzer cargo itertools 0.14.0 iter_index/impl#[`RangeTo<usize>`][`IteratorIndex<I>`]::Outputrust-analyzer cargo itertools 0.14.0 iter_index/IteratorIndex#Output# { |
| 72 | iter.takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(self.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#end.) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | impl<I> IteratorIndexrust-analyzer cargo itertools 0.14.0 iter_index/IteratorIndex#<I> for RangeToInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeToInclusive#<usize> |
| 77 | where |
| 78 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, |
| 79 | { |
| 80 | type Outputrust-analyzer cargo itertools 0.14.0 iter_index/impl#[`RangeToInclusive<usize>`][`IteratorIndex<I>`]Output# = Takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/take/Take#<I>; |
| 81 | |
| 82 | fn indexrust-analyzer cargo itertools 0.14.0 iter_index/impl#[`RangeToInclusive<usize>`][`IteratorIndex<I>`]index().(self, iter: I) -> Selfrust-analyzer cargo itertools 0.14.0 iter_index/impl#[`RangeToInclusive<usize>`][`IteratorIndex<I>`]::Outputrust-analyzer cargo itertools 0.14.0 iter_index/IteratorIndex#Output# { |
| 83 | assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_ne!!(self.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeToInclusive#end., usize::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]MAX.); |
| 84 | iter.takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(self.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeToInclusive#end. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | impl<I> IteratorIndexrust-analyzer cargo itertools 0.14.0 iter_index/IteratorIndex#<I> for RangeFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#<usize> |
| 89 | where |
| 90 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, |
| 91 | { |
| 92 | type Outputrust-analyzer cargo itertools 0.14.0 iter_index/impl#[`RangeFrom<usize>`][`IteratorIndex<I>`]Output# = Skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/skip/Skip#<I>; |
| 93 | |
| 94 | fn indexrust-analyzer cargo itertools 0.14.0 iter_index/impl#[`RangeFrom<usize>`][`IteratorIndex<I>`]index().(self, iter: I) -> Selfrust-analyzer cargo itertools 0.14.0 iter_index/impl#[`RangeFrom<usize>`][`IteratorIndex<I>`]::Outputrust-analyzer cargo itertools 0.14.0 iter_index/IteratorIndex#Output# { |
| 95 | iter.skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(self.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#start.) |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | impl<I> IteratorIndexrust-analyzer cargo itertools 0.14.0 iter_index/IteratorIndex#<I> for RangeFullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull# |
| 100 | where |
| 101 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, |
| 102 | { |
| 103 | type Outputrust-analyzer cargo itertools 0.14.0 iter_index/impl#[RangeFull][`IteratorIndex<I>`]Output# = I; |
| 104 | |
| 105 | fn indexrust-analyzer cargo itertools 0.14.0 iter_index/impl#[RangeFull][`IteratorIndex<I>`]index().(self, iter: I) -> Selfrust-analyzer cargo itertools 0.14.0 iter_index/impl#[RangeFull][`IteratorIndex<I>`]::Outputrust-analyzer cargo itertools 0.14.0 iter_index/IteratorIndex#Output# { |
| 106 | iter |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | pub fn getrust-analyzer cargo itertools 0.14.0 iter_index/get().<I, R>(iter: I, index: R) -> R::Outputrust-analyzer cargo itertools 0.14.0 iter_index/IteratorIndex#Output# |
| 111 | where |
| 112 | I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#, |
| 113 | R: IteratorIndexrust-analyzer cargo itertools 0.14.0 iter_index/IteratorIndex#<I::IntoIterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#IntoIter#>, |
| 114 | { |
| 115 | index.indexrust-analyzer cargo itertools 0.14.0 iter_index/IteratorIndex#index().(iter.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().()) |
| 116 | } |