| 1 | //! Some iterator that produces tuples |
| 2 | |
| 3 | use 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/::Cyclerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/cycle/Cycle#; |
| 4 | use 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/::Fuserust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/Fuse#; |
| 5 | use 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#; |
| 6 | |
| 7 | use craterust-analyzer cargo itertools 0.14.0 crate/::size_hintrust-analyzer cargo itertools 0.14.0 size_hint/; |
| 8 | |
| 9 | // `HomogeneousTuple` is a public facade for `TupleCollect`, allowing |
| 10 | // tuple-related methods to be used by clients in generic contexts, while |
| 11 | // hiding the implementation details of `TupleCollect`. |
| 12 | // See https://github.com/rust-itertools/itertools/issues/387 |
| 13 | |
| 14 | /// Implemented for homogeneous tuples of size up to 12. |
| 15 | pub trait HomogeneousTuplerust-analyzer cargo itertools 0.14.0 tuple_impl/HomogeneousTuple#: TupleCollectrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect# {} |
| 16 | |
| 17 | impl<T: TupleCollectrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#> HomogeneousTuplerust-analyzer cargo itertools 0.14.0 tuple_impl/HomogeneousTuple# for T {} |
| 18 | |
| 19 | /// An iterator over a incomplete tuple. |
| 20 | /// |
| 21 | /// See [`.tuples()`](crate::Itertools::tuples) and |
| 22 | /// [`Tuples::into_buffer()`]. |
| 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:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 24 | pub struct TupleBufferrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleBuffer#<T> |
| 25 | where |
| 26 | T: HomogeneousTuplerust-analyzer cargo itertools 0.14.0 tuple_impl/HomogeneousTuple#, |
| 27 | { |
| 28 | currust-analyzer cargo itertools 0.14.0 tuple_impl/TupleBuffer#cur.: usize, |
| 29 | bufrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleBuffer#buf.: T::Bufferrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Buffer#, |
| 30 | } |
| 31 | |
| 32 | impl<T> TupleBufferrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleBuffer#<T> |
| 33 | where |
| 34 | T: HomogeneousTuplerust-analyzer cargo itertools 0.14.0 tuple_impl/HomogeneousTuple#, |
| 35 | { |
| 36 | fn newrust-analyzer cargo itertools 0.14.0 tuple_impl/impl#[`TupleBuffer<T>`]new().(buf: T::Bufferrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Buffer#) -> Selfrust-analyzer cargo itertools 0.14.0 tuple_impl/impl#[`TupleBuffer<T>`] { |
| 37 | Selfrust-analyzer cargo itertools 0.14.0 tuple_impl/impl#[`TupleBuffer<T>`] { currust-analyzer cargo itertools 0.14.0 tuple_impl/TupleBuffer#cur.: 0, bufrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleBuffer#buf. } |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | impl<T> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for TupleBufferrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleBuffer#<T> |
| 42 | where |
| 43 | T: HomogeneousTuplerust-analyzer cargo itertools 0.14.0 tuple_impl/HomogeneousTuple#, |
| 44 | { |
| 45 | type Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/impl#[`TupleBuffer<T>`][Iterator]Item# = T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#; |
| 46 | |
| 47 | fn nextrust-analyzer cargo itertools 0.14.0 tuple_impl/impl#[`TupleBuffer<T>`][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 tuple_impl/impl#[`TupleBuffer<T>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 48 | let s = self.bufrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleBuffer#buf..as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsMut#as_mut().(); |
| 49 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref mut item) = s.get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_mut().(self.currust-analyzer cargo itertools 0.14.0 tuple_impl/TupleBuffer#cur.) { |
| 50 | self.currust-analyzer cargo itertools 0.14.0 tuple_impl/TupleBuffer#cur. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 51 | item.takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() |
| 52 | } else { |
| 53 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | fn size_hintrust-analyzer cargo itertools 0.14.0 tuple_impl/impl#[`TupleBuffer<T>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 58 | let buffer = &self.bufrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleBuffer#buf..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().self.currust-analyzer cargo itertools 0.14.0 tuple_impl/TupleBuffer#cur...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 59 | let len = if buffer.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 60 | 0 |
| 61 | } else { |
| 62 | buffer |
| 63 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 64 | .positionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]position().(|x| x.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()) |
| 65 | .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(buffer.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()) |
| 66 | }; |
| 67 | (len, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(len)) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | impl<T> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for TupleBufferrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleBuffer#<T> where T: HomogeneousTuplerust-analyzer cargo itertools 0.14.0 tuple_impl/HomogeneousTuple# {} |
| 72 | |
| 73 | /// An iterator that groups the items in tuples of a specific size. |
| 74 | /// |
| 75 | /// See [`.tuples()`](crate::Itertools::tuples) for more information. |
| 76 | #[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:)] |
| 77 | #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] |
| 78 | pub struct Tuplesrust-analyzer cargo itertools 0.14.0 tuple_impl/Tuples#<I, T> |
| 79 | where |
| 80 | I: 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# = T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#>, |
| 81 | T: HomogeneousTuplerust-analyzer cargo itertools 0.14.0 tuple_impl/HomogeneousTuple#, |
| 82 | { |
| 83 | iterrust-analyzer cargo itertools 0.14.0 tuple_impl/Tuples#iter.: Fuserust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/Fuse#<I>, |
| 84 | bufrust-analyzer cargo itertools 0.14.0 tuple_impl/Tuples#buf.: T::Bufferrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Buffer#, |
| 85 | } |
| 86 | |
| 87 | /// Create a new tuples iterator. |
| 88 | pub fn tuplesrust-analyzer cargo itertools 0.14.0 tuple_impl/tuples().<I, T>(iter: I) -> Tuplesrust-analyzer cargo itertools 0.14.0 tuple_impl/Tuples#<I, T> |
| 89 | where |
| 90 | I: 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# = T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#>, |
| 91 | T: HomogeneousTuplerust-analyzer cargo itertools 0.14.0 tuple_impl/HomogeneousTuple#, |
| 92 | { |
| 93 | Tuplesrust-analyzer cargo itertools 0.14.0 tuple_impl/Tuples# { |
| 94 | iterrust-analyzer cargo itertools 0.14.0 tuple_impl/Tuples#iter.: iter.fuserust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#fuse().(), |
| 95 | bufrust-analyzer cargo itertools 0.14.0 tuple_impl/Tuples#buf.: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#default().(), |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | impl<I, T> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Tuplesrust-analyzer cargo itertools 0.14.0 tuple_impl/Tuples#<I, T> |
| 100 | where |
| 101 | I: 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# = T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#>, |
| 102 | T: HomogeneousTuplerust-analyzer cargo itertools 0.14.0 tuple_impl/HomogeneousTuple#, |
| 103 | { |
| 104 | type Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/impl#[`Tuples<I, T>`][Iterator]Item# = T; |
| 105 | |
| 106 | fn nextrust-analyzer cargo itertools 0.14.0 tuple_impl/impl#[`Tuples<I, T>`][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 tuple_impl/impl#[`Tuples<I, T>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 107 | T::collect_from_iterrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#collect_from_iter().(&mut self.iterrust-analyzer cargo itertools 0.14.0 tuple_impl/Tuples#iter., &mut self.bufrust-analyzer cargo itertools 0.14.0 tuple_impl/Tuples#buf.) |
| 108 | } |
| 109 | |
| 110 | fn size_hintrust-analyzer cargo itertools 0.14.0 tuple_impl/impl#[`Tuples<I, T>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 111 | // The number of elts we've drawn from the underlying iterator, but have |
| 112 | // not yet produced as a tuple. |
| 113 | let buffered = T::buffer_lenrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#buffer_len().(&self.bufrust-analyzer cargo itertools 0.14.0 tuple_impl/Tuples#buf.); |
| 114 | // To that, we must add the size estimates of the underlying iterator. |
| 115 | let (unbuffered_lo, unbuffered_hi) = self.iterrust-analyzer cargo itertools 0.14.0 tuple_impl/Tuples#iter..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]size_hint().(); |
| 116 | // The total low estimate is the sum of the already-buffered elements, |
| 117 | // plus the low estimate of remaining unbuffered elements, divided by |
| 118 | // the tuple size. |
| 119 | let total_lo = add_then_divrust-analyzer cargo itertools 0.14.0 tuple_impl/add_then_div().(unbuffered_lo, buffered, T::num_itemsrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#num_items().()).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(usize::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]MAX.); |
| 120 | // And likewise for the total high estimate, but using the high estimate |
| 121 | // of the remaining unbuffered elements. |
| 122 | let total_hi = unbuffered_hi.and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|hi| add_then_divrust-analyzer cargo itertools 0.14.0 tuple_impl/add_then_div().(hi, buffered, T::num_itemsrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#num_items().())); |
| 123 | (total_lo, total_hi) |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /// `(n + a) / d` avoiding overflow when possible, returns `None` if it overflows. |
| 128 | fn add_then_divrust-analyzer cargo itertools 0.14.0 tuple_impl/add_then_div().(n: usize, a: usize, d: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize> { |
| 129 | debug_assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert_ne!!(d, 0); |
| 130 | (n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().d).checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(a rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().d)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().((n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().d 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().a rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().d) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().d) |
| 131 | } |
| 132 | |
| 133 | impl<I, T> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for Tuplesrust-analyzer cargo itertools 0.14.0 tuple_impl/Tuples#<I, T> |
| 134 | where |
| 135 | I: ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#>, |
| 136 | T: HomogeneousTuplerust-analyzer cargo itertools 0.14.0 tuple_impl/HomogeneousTuple#, |
| 137 | { |
| 138 | } |
| 139 | |
| 140 | impl<I, T> Tuplesrust-analyzer cargo itertools 0.14.0 tuple_impl/Tuples#<I, T> |
| 141 | where |
| 142 | I: 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# = T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#>, |
| 143 | T: HomogeneousTuplerust-analyzer cargo itertools 0.14.0 tuple_impl/HomogeneousTuple#, |
| 144 | { |
| 145 | /// Return a buffer with the produced items that was not enough to be grouped in a tuple. |
| 146 | /// |
| 147 | /// ``` |
| 148 | /// use itertools::Itertools; |
| 149 | /// |
| 150 | /// let mut iter = (0..5).tuples(); |
| 151 | /// assert_eq!(Some((0, 1, 2)), iter.next()); |
| 152 | /// assert_eq!(None, iter.next()); |
| 153 | /// itertools::assert_equal(vec![3, 4], iter.into_buffer()); |
| 154 | /// ``` |
| 155 | pub fn into_bufferrust-analyzer cargo itertools 0.14.0 tuple_impl/impl#[`Tuples<I, T>`]into_buffer().(self) -> TupleBufferrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleBuffer#<T> { |
| 156 | TupleBufferrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleBuffer#::newrust-analyzer cargo itertools 0.14.0 tuple_impl/impl#[`TupleBuffer<T>`]new().(self.bufrust-analyzer cargo itertools 0.14.0 tuple_impl/Tuples#buf.) |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | /// An iterator over all contiguous windows that produces tuples of a specific size. |
| 161 | /// |
| 162 | /// See [`.tuple_windows()`](crate::Itertools::tuple_windows) for more |
| 163 | /// information. |
| 164 | #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] |
| 165 | #[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:)] |
| 166 | pub struct TupleWindowsrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleWindows#<I, T> |
| 167 | where |
| 168 | I: 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# = T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#>, |
| 169 | T: HomogeneousTuplerust-analyzer cargo itertools 0.14.0 tuple_impl/HomogeneousTuple#, |
| 170 | { |
| 171 | iterrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleWindows#iter.: I, |
| 172 | lastrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleWindows#last.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T>, |
| 173 | } |
| 174 | |
| 175 | /// Create a new tuple windows iterator. |
| 176 | pub fn tuple_windowsrust-analyzer cargo itertools 0.14.0 tuple_impl/tuple_windows().<I, T>(iter: I) -> TupleWindowsrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleWindows#<I, T> |
| 177 | where |
| 178 | I: 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# = T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#>, |
| 179 | T: HomogeneousTuplerust-analyzer cargo itertools 0.14.0 tuple_impl/HomogeneousTuple#, |
| 180 | T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 181 | { |
| 182 | TupleWindowsrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleWindows# { lastrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleWindows#last.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, iterrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleWindows#iter. } |
| 183 | } |
| 184 | |
| 185 | impl<I, T> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for TupleWindowsrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleWindows#<I, T> |
| 186 | where |
| 187 | I: 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# = T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#>, |
| 188 | T: HomogeneousTuplerust-analyzer cargo itertools 0.14.0 tuple_impl/HomogeneousTuple# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 189 | T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 190 | { |
| 191 | type Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/impl#[`TupleWindows<I, T>`][Iterator]Item# = T; |
| 192 | |
| 193 | fn nextrust-analyzer cargo itertools 0.14.0 tuple_impl/impl#[`TupleWindows<I, T>`][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 tuple_impl/impl#[`TupleWindows<I, T>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 194 | if T::num_itemsrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#num_items().() 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().1 { |
| 195 | return T::collect_from_iter_no_bufrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#collect_from_iter_no_buf().(&mut self.iterrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleWindows#iter.); |
| 196 | } |
| 197 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(new) = self.iterrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleWindows#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() { |
| 198 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref mut last) = self.lastrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleWindows#last. { |
| 199 | last.left_shift_pushrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#left_shift_push().(new); |
| 200 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(last.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()) |
| 201 | } else { |
| 202 | use 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/::oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().; |
| 203 | let iter = oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().(new).chainrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#chain().(&mut self.iterrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleWindows#iter.); |
| 204 | self.lastrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleWindows#last. = T::collect_from_iter_no_bufrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#collect_from_iter_no_buf().(iter); |
| 205 | self.lastrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleWindows#last..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Clone]clone().() |
| 206 | } |
| 207 | } else { |
| 208 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | fn size_hintrust-analyzer cargo itertools 0.14.0 tuple_impl/impl#[`TupleWindows<I, T>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 213 | let mut sh = self.iterrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleWindows#iter..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().(); |
| 214 | // Adjust the size hint at the beginning |
| 215 | // OR when `num_items == 1` (but it does not change the size hint). |
| 216 | if self.lastrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleWindows#last..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() { |
| 217 | sh = size_hintrust-analyzer cargo itertools 0.14.0 size_hint/::sub_scalarrust-analyzer cargo itertools 0.14.0 size_hint/sub_scalar().(sh, T::num_itemsrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#num_items().() 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().1); |
| 218 | } |
| 219 | sh |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | impl<I, T> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for TupleWindowsrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleWindows#<I, T> |
| 224 | where |
| 225 | I: ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#>, |
| 226 | T: HomogeneousTuplerust-analyzer cargo itertools 0.14.0 tuple_impl/HomogeneousTuple# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 227 | T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 228 | { |
| 229 | } |
| 230 | |
| 231 | impl<I, T> FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for TupleWindowsrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleWindows#<I, T> |
| 232 | where |
| 233 | I: FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#>, |
| 234 | T: HomogeneousTuplerust-analyzer cargo itertools 0.14.0 tuple_impl/HomogeneousTuple# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 235 | T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 236 | { |
| 237 | } |
| 238 | |
| 239 | /// An iterator over all windows, wrapping back to the first elements when the |
| 240 | /// window would otherwise exceed the length of the iterator, producing tuples |
| 241 | /// of a specific size. |
| 242 | /// |
| 243 | /// See [`.circular_tuple_windows()`](crate::Itertools::circular_tuple_windows) for more |
| 244 | /// information. |
| 245 | #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] |
| 246 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 247 | pub struct CircularTupleWindowsrust-analyzer cargo itertools 0.14.0 tuple_impl/CircularTupleWindows#<I, T> |
| 248 | where |
| 249 | I: 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# = T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#> + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 250 | T: TupleCollectrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 251 | { |
| 252 | iterrust-analyzer cargo itertools 0.14.0 tuple_impl/CircularTupleWindows#iter.: TupleWindowsrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleWindows#<Cyclerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/cycle/Cycle#<I>, T>, |
| 253 | lenrust-analyzer cargo itertools 0.14.0 tuple_impl/CircularTupleWindows#len.: usize, |
| 254 | } |
| 255 | |
| 256 | pub fn circular_tuple_windowsrust-analyzer cargo itertools 0.14.0 tuple_impl/circular_tuple_windows().<I, T>(iter: I) -> CircularTupleWindowsrust-analyzer cargo itertools 0.14.0 tuple_impl/CircularTupleWindows#<I, T> |
| 257 | where |
| 258 | I: 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# = T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#> + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#, |
| 259 | T: TupleCollectrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 260 | T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 261 | { |
| 262 | let len = iter.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#len().(); |
| 263 | let iter = tuple_windowsrust-analyzer cargo itertools 0.14.0 tuple_impl/tuple_windows().(iter.cyclerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cycle().()); |
| 264 | |
| 265 | CircularTupleWindowsrust-analyzer cargo itertools 0.14.0 tuple_impl/CircularTupleWindows# { iterrust-analyzer cargo itertools 0.14.0 tuple_impl/CircularTupleWindows#iter., lenrust-analyzer cargo itertools 0.14.0 tuple_impl/CircularTupleWindows#len. } |
| 266 | } |
| 267 | |
| 268 | impl<I, T> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for CircularTupleWindowsrust-analyzer cargo itertools 0.14.0 tuple_impl/CircularTupleWindows#<I, T> |
| 269 | where |
| 270 | I: 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# = T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#> + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 271 | T: TupleCollectrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 272 | T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 273 | { |
| 274 | type Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/impl#[`CircularTupleWindows<I, T>`][Iterator]Item# = T; |
| 275 | |
| 276 | fn nextrust-analyzer cargo itertools 0.14.0 tuple_impl/impl#[`CircularTupleWindows<I, T>`][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 tuple_impl/impl#[`CircularTupleWindows<I, T>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 277 | if self.lenrust-analyzer cargo itertools 0.14.0 tuple_impl/CircularTupleWindows#len. 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 { |
| 278 | self.lenrust-analyzer cargo itertools 0.14.0 tuple_impl/CircularTupleWindows#len. 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; |
| 279 | self.iterrust-analyzer cargo itertools 0.14.0 tuple_impl/CircularTupleWindows#iter..nextrust-analyzer cargo itertools 0.14.0 tuple_impl/impl#[`TupleWindows<I, T>`][Iterator]next().() |
| 280 | } else { |
| 281 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | fn size_hintrust-analyzer cargo itertools 0.14.0 tuple_impl/impl#[`CircularTupleWindows<I, T>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 286 | (self.lenrust-analyzer cargo itertools 0.14.0 tuple_impl/CircularTupleWindows#len., Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.lenrust-analyzer cargo itertools 0.14.0 tuple_impl/CircularTupleWindows#len.)) |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | impl<I, T> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for CircularTupleWindowsrust-analyzer cargo itertools 0.14.0 tuple_impl/CircularTupleWindows#<I, T> |
| 291 | where |
| 292 | I: 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# = T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#> + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 293 | T: TupleCollectrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 294 | T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 295 | { |
| 296 | } |
| 297 | |
| 298 | impl<I, T> FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for CircularTupleWindowsrust-analyzer cargo itertools 0.14.0 tuple_impl/CircularTupleWindows#<I, T> |
| 299 | where |
| 300 | I: 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# = T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#> + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 301 | T: TupleCollectrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 302 | T::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 303 | { |
| 304 | } |
| 305 | |
| 306 | pub trait TupleCollectrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# { |
| 307 | type Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#; |
| 308 | type Bufferrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Buffer#: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# + AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#>]> + AsMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsMut#<[Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#>]>; |
| 309 | |
| 310 | fn buffer_lenrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#buffer_len().(buf: &Self::Bufferrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Buffer#) -> usize { |
| 311 | let s = buf.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(); |
| 312 | s.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().positionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]position().(Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#::is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(s.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()) |
| 313 | } |
| 314 | |
| 315 | fn collect_from_iterrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#collect_from_iter().<I>(iter: I, buf: &mut Self::Bufferrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Buffer#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self> |
| 316 | where |
| 317 | I: 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# = Self::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#>; |
| 318 | |
| 319 | fn collect_from_iter_no_bufrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#collect_from_iter_no_buf().<I>(iter: I) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self> |
| 320 | where |
| 321 | I: 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# = Self::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#>; |
| 322 | |
| 323 | fn num_itemsrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#num_items().() -> usize; |
| 324 | |
| 325 | fn left_shift_pushrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#left_shift_push().(&mut self, item: Self::Itemrust-analyzer cargo itertools 0.14.0 tuple_impl/TupleCollect#Item#); |
| 326 | } |
| 327 | |
| 328 | macro_rules! rev_for_each_identrust-analyzer cargo itertools 0.14.0 tuple_impl/rev_for_each_ident!{ |
| 329 | ($m:ident, ) => {}; |
| 330 | ($m:ident, $i0:ident, $($i:ident,)*) => { |
| 331 | rev_for_each_ident!($m, $($i,)*); |
| 332 | $m!($i0); |
| 333 | }; |
| 334 | } |
| 335 | |
| 336 | macro_rules! impl_tuple_collectrust-analyzer cargo itertools 0.14.0 tuple_impl/impl_tuple_collect! { |
| 337 | ($dummy:ident,) => {}; // stop |
| 338 | ($dummy:ident, $($Y:ident,)*) => ( |
| 339 | impl_tuple_collect!($($Y,)*); |
| 340 | impl<A> TupleCollect for ($(ignore_ident!($Y, A),)*) { |
| 341 | type Item = A; |
| 342 | type Buffer = [Option<A>; count_ident!($($Y)*) - 1]; |
| 343 | |
| 344 | #[allow(unused_assignments, unused_mut)] |
| 345 | fn collect_from_iter<I>(iter: I, buf: &mut Self::Buffer) -> Option<Self> |
| 346 | where I: IntoIterator<Item = A> |
| 347 | { |
| 348 | let mut iter = iter.into_iter(); |
| 349 | $( |
| 350 | let mut $Y = None; |
| 351 | )* |
| 352 | |
| 353 | loop { |
| 354 | $( |
| 355 | $Y = iter.next(); |
| 356 | if $Y.is_none() { |
| 357 | break |
| 358 | } |
| 359 | )* |
| 360 | return Some(($($Y.unwrap()),*,)) |
| 361 | } |
| 362 | |
| 363 | let mut i = 0; |
| 364 | let mut s = buf.as_mut(); |
| 365 | $( |
| 366 | if i < s.len() { |
| 367 | s[i] = $Y; |
| 368 | i += 1; |
| 369 | } |
| 370 | )* |
| 371 | return None; |
| 372 | } |
| 373 | |
| 374 | fn collect_from_iter_no_buf<I>(iter: I) -> Option<Self> |
| 375 | where I: IntoIterator<Item = A> |
| 376 | { |
| 377 | let mut iter = iter.into_iter(); |
| 378 | |
| 379 | Some(($( |
| 380 | { let $Y = iter.next()?; $Y }, |
| 381 | )*)) |
| 382 | } |
| 383 | |
| 384 | fn num_items() -> usize { |
| 385 | count_ident!($($Y)*) |
| 386 | } |
| 387 | |
| 388 | fn left_shift_push(&mut self, mut item: A) { |
| 389 | use std::mem::replace; |
| 390 | |
| 391 | let &mut ($(ref mut $Y),*,) = self; |
| 392 | macro_rules! replace_item{($i:ident) => { |
| 393 | item = replace($i, item); |
| 394 | }} |
| 395 | rev_for_each_ident!(replace_item, $($Y,)*); |
| 396 | drop(item); |
| 397 | } |
| 398 | } |
| 399 | ) |
| 400 | } |
| 401 | impl_tuple_collectrust-analyzer cargo itertools 0.14.0 tuple_impl/impl_tuple_collect!!(dummy, a, b, c, d, e, f, g, h, i, j, k, l,); |