| 1 | #![cfg(feature = "use_alloc")] |
| 2 | use Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#::{selfrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option# as Staterust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# as ProductEndedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some# as ProductInProgressrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#}; |
| 3 | use Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#::{selfrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option# as CurrentItemsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# as NotYetPopulatedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some# as Populatedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#}; |
| 4 | |
| 5 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#; |
| 6 | |
| 7 | use craterust-analyzer cargo itertools 0.14.0 crate/::size_hintrust-analyzer cargo itertools 0.14.0 size_hint/; |
| 8 | |
| 9 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 10 | /// An iterator adaptor that iterates over the cartesian product of |
| 11 | /// multiple iterators of type `I`. |
| 12 | /// |
| 13 | /// An iterator element type is `Vec<I::Item>`. |
| 14 | /// |
| 15 | /// See [`.multi_cartesian_product()`](crate::Itertools::multi_cartesian_product) |
| 16 | /// for more information. |
| 17 | #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] |
| 18 | pub struct MultiProductrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProduct#<I>(Staterust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<MultiProductInnerrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#<I>>) |
| 19 | where |
| 20 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 21 | I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#; |
| 22 | |
| 23 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 24 | /// Internals for `MultiProduct`. |
| 25 | struct MultiProductInnerrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#<I> |
| 26 | where |
| 27 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 28 | I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 29 | { |
| 30 | /// Holds the iterators. |
| 31 | itersrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#iters.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<MultiProductIterrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#<I>>, |
| 32 | /// Not populated at the beginning then it holds the current item of each iterator. |
| 33 | currust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#cur.: CurrentItemsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#>>, |
| 34 | } |
| 35 | |
| 36 | impl<I> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for MultiProductrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProduct#<I> |
| 37 | where |
| 38 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, |
| 39 | I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, |
| 40 | { |
| 41 | debug_fmt_fieldsrust-analyzer cargo itertools 0.14.0 impl_macros/debug_fmt_fields!!(MultiProduct, 0rust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProduct#0.); |
| 42 | } |
| 43 | |
| 44 | impl<I> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for MultiProductInnerrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#<I> |
| 45 | where |
| 46 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, |
| 47 | I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, |
| 48 | { |
| 49 | debug_fmt_fieldsrust-analyzer cargo itertools 0.14.0 impl_macros/debug_fmt_fields!!(MultiProductInner, itersrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#iters., currust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#cur.); |
| 50 | } |
| 51 | |
| 52 | /// Create a new cartesian product iterator over an arbitrary number |
| 53 | /// of iterators of the same type. |
| 54 | /// |
| 55 | /// Iterator element is of type `Vec<H::Item::Item>`. |
| 56 | pub fn multi_cartesian_productrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/multi_cartesian_product().<H>(iters: H) -> MultiProductrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProduct#<<H::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# as IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#>::IntoIterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#IntoIter#> |
| 57 | where |
| 58 | H: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, |
| 59 | H::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#, |
| 60 | <H::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# as IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#>::IntoIterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#IntoIter#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 61 | <H::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# as IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#>::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 62 | { |
| 63 | let inner = MultiProductInnerrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner# { |
| 64 | itersrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#iters.: iters |
| 65 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|i| MultiProductIterrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#::newrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/impl#[`MultiProductIter<I>`]new().(i.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().())) |
| 66 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(), |
| 67 | currust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#cur.: NotYetPopulatedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 68 | }; |
| 69 | MultiProductrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProduct#(ProductInProgressrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(inner)) |
| 70 | } |
| 71 | |
| 72 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 73 | /// Holds the state of a single iterator within a `MultiProduct`. |
| 74 | struct MultiProductIterrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#<I> |
| 75 | where |
| 76 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 77 | I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 78 | { |
| 79 | iterrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#iter.: I, |
| 80 | iter_origrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#iter_orig.: I, |
| 81 | } |
| 82 | |
| 83 | impl<I> MultiProductIterrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#<I> |
| 84 | where |
| 85 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 86 | I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 87 | { |
| 88 | fn newrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/impl#[`MultiProductIter<I>`]new().(iter: I) -> Selfrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/impl#[`MultiProductIter<I>`] { |
| 89 | Selfrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/impl#[`MultiProductIter<I>`] { |
| 90 | iterrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#iter.: iter.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), |
| 91 | iter_origrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#iter_orig.: iter, |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | impl<I> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for MultiProductrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProduct#<I> |
| 97 | where |
| 98 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 99 | I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 100 | { |
| 101 | type Itemrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/impl#[`MultiProduct<I>`][Iterator]Item# = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#>; |
| 102 | |
| 103 | fn nextrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/impl#[`MultiProduct<I>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/impl#[`MultiProduct<I>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 104 | // This fuses the iterator. |
| 105 | let inner = self.0rust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProduct#0..as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 106 | match &mut inner.currust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#cur. { |
| 107 | Populatedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(values) => { |
| 108 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().inner.itersrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#iters..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 109 | // Find (from the right) a non-finished iterator and |
| 110 | // reset the finished ones encountered. |
| 111 | for (iter, item) in inner.itersrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#iters..iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(values.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().()).revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().() { |
| 112 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(new) = iter.iterrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() { |
| 113 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().item = new; |
| 114 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(values.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().()); |
| 115 | } else { |
| 116 | iter.iterrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#iter. = iter.iter_origrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#iter_orig..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(); |
| 117 | // `cur` is populated so the untouched `iter_orig` can not be empty. |
| 118 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().item = iter.iterrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 119 | } |
| 120 | } |
| 121 | self.0rust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProduct#0. = ProductEndedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 122 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 123 | } |
| 124 | // Only the first time. |
| 125 | NotYetPopulatedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 126 | let next: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>> = inner.itersrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#iters..iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|i| i.iterrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 127 | if next.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() || inner.itersrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#iters..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 128 | // This cartesian product had at most one item to generate and now ends. |
| 129 | self.0rust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProduct#0. = ProductEndedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 130 | } else { |
| 131 | inner.currust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#cur..clone_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Clone]clone_from().(&next); |
| 132 | } |
| 133 | next |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | fn countrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/impl#[`MultiProduct<I>`][Iterator]count().(self) -> usize { |
| 139 | match self.0rust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProduct#0. { |
| 140 | ProductEndedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => 0, |
| 141 | // The iterator is fresh so the count is the product of the length of each iterator: |
| 142 | // - If one of them is empty, stop counting. |
| 143 | // - Less `count()` calls than the general case. |
| 144 | ProductInProgressrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(MultiProductInnerrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner# { |
| 145 | itersrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#iters., |
| 146 | currust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#cur.: NotYetPopulatedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 147 | }) => iters |
| 148 | .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().() |
| 149 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|iter| iter.iter_origrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#iter_orig..countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().()) |
| 150 | .try_foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/map/impl#[`Map<I, F>`][Iterator]try_fold().(1, |product, count| { |
| 151 | if count 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().0 { |
| 152 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 153 | } else { |
| 154 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(product rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().count) |
| 155 | } |
| 156 | }) |
| 157 | .unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().(), |
| 158 | // The general case. |
| 159 | ProductInProgressrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(MultiProductInnerrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner# { |
| 160 | itersrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#iters., |
| 161 | currust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#cur.: Populatedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_), |
| 162 | }) => iters.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().foldrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/into_iter/impl#[`IntoIter<T, A>`][Iterator]fold().(0, |mut acc, iter| { |
| 163 | if acc rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0 { |
| 164 | acc rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`MulAssign<Self>`]mul_assign().*=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`MulAssign<Self>`]mul_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`MulAssign<Self>`]mul_assign().iter.iter_origrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#iter_orig..countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(); |
| 165 | } |
| 166 | acc 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().iter.iterrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#iter..countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().() |
| 167 | }), |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | fn size_hintrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/impl#[`MultiProduct<I>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 172 | match &self.0rust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProduct#0. { |
| 173 | ProductEndedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0)), |
| 174 | ProductInProgressrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(MultiProductInnerrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner# { |
| 175 | itersrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#iters., |
| 176 | currust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#cur.: NotYetPopulatedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 177 | }) => iters |
| 178 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 179 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|iter| iter.iter_origrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#iter_orig..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().()) |
| 180 | .foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/map/impl#[`Map<I, F>`][Iterator]fold().((1, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1)), size_hintrust-analyzer cargo itertools 0.14.0 size_hint/::mulrust-analyzer cargo itertools 0.14.0 size_hint/mul().), |
| 181 | ProductInProgressrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(MultiProductInnerrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner# { |
| 182 | itersrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#iters., |
| 183 | currust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#cur.: Populatedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_), |
| 184 | }) => { |
| 185 | if let [first, tail @ ..] = &iters[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). { |
| 186 | tail.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]fold().(first.iterrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#iter..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().(), |mut sh, iter| { |
| 187 | sh = size_hintrust-analyzer cargo itertools 0.14.0 size_hint/::mulrust-analyzer cargo itertools 0.14.0 size_hint/mul().(sh, iter.iter_origrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#iter_orig..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().()); |
| 188 | size_hintrust-analyzer cargo itertools 0.14.0 size_hint/::addrust-analyzer cargo itertools 0.14.0 size_hint/add().(sh, iter.iterrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#iter..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().()) |
| 189 | }) |
| 190 | } else { |
| 191 | // Since it is populated, this cartesian product has started so `iters` is not empty. |
| 192 | unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!() |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | fn lastrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/impl#[`MultiProduct<I>`][Iterator]last().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/impl#[`MultiProduct<I>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 199 | let MultiProductInnerrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner# { itersrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#iters., currust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductInner#cur. } = self.0rust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProduct#0.?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 200 | // Collect the last item of each iterator of the product. |
| 201 | if let Populatedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(values) = cur { |
| 202 | let mut count = iters.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 203 | let last = iters |
| 204 | .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().() |
| 205 | .ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(values) |
| 206 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(i, value)| { |
| 207 | i.iterrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#iter..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#last().().unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| { |
| 208 | // The iterator is empty, use its current `value`. |
| 209 | count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1; |
| 210 | value |
| 211 | }) |
| 212 | }) |
| 213 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 214 | if count 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().0 { |
| 215 | // `values` was the last item. |
| 216 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 217 | } else { |
| 218 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(last) |
| 219 | } |
| 220 | } else { |
| 221 | iters.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|i| i.iterrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProductIter#iter..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#last().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().() |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | impl<I> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for MultiProductrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/MultiProduct#<I> |
| 227 | where |
| 228 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 229 | I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 230 | { |
| 231 | } |