Debian Codegraph @

debian/missing-sources/itertools/src/adaptors/mod.rs

raw symbols SCIP
1 //! Licensed under the Apache License, Version 2.0
2 //! <https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3 //! <https://opensource.org/licenses/MIT>, at your
4 //! option. This file may not be copied, modified, or distributed
5 //! except according to those terms.
6
7 mod coalescerust-analyzer cargo itertools 0.14.0 adaptors/coalesce/;
8 pub(craterust-analyzer cargo itertools 0.14.0 crate/) mod maprust-analyzer cargo itertools 0.14.0 adaptors/map/;
9 mod multi_productrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/;
10 pub use selfrust-analyzer cargo itertools 0.14.0 adaptors/::coalescerust-analyzer cargo itertools 0.14.0 adaptors/coalesce/::*;
11 pub use selfrust-analyzer cargo itertools 0.14.0 adaptors/::maprust-analyzer cargo itertools 0.14.0 adaptors/map/::{map_intorust-analyzer cargo itertools 0.14.0 adaptors/map/map_into()., map_okrust-analyzer cargo itertools 0.14.0 adaptors/map/map_ok()., MapIntorust-analyzer cargo itertools 0.14.0 adaptors/map/MapInto#, MapOkrust-analyzer cargo itertools 0.14.0 adaptors/map/MapOk#};
12 #[cfg(feature = "use_alloc")]
13 pub use selfrust-analyzer cargo itertools 0.14.0 adaptors/::multi_productrust-analyzer cargo itertools 0.14.0 adaptors/multi_product/::*;
14
15 use craterust-analyzer cargo itertools 0.14.0 crate/::size_hintrust-analyzer cargo itertools 0.14.0 size_hint/::{selfrust-analyzer cargo itertools 0.14.0 size_hint/, SizeHintrust-analyzer cargo itertools 0.14.0 size_hint/SizeHint#};
16 use 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/;
17 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/::{Enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/enumerate/Enumerate#, FromIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/FromIterator#, Fuserust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/Fuse#, FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator#};
18 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#;
19
20 /// An iterator adaptor that alternates elements from two iterators until both
21 /// run out.
22 ///
23 /// This iterator is *fused*.
24 ///
25 /// See [`.interleave()`](crate::Itertools::interleave) for more information.
26 #[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:)]
27 #[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
28 pub struct Interleaverust-analyzer cargo itertools 0.14.0 adaptors/Interleave#<I, J> {
29 irust-analyzer cargo itertools 0.14.0 adaptors/Interleave#i.: Fuserust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/Fuse#<I>,
30 jrust-analyzer cargo itertools 0.14.0 adaptors/Interleave#j.: Fuserust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/Fuse#<J>,
31 next_coming_from_jrust-analyzer cargo itertools 0.14.0 adaptors/Interleave#next_coming_from_j.: bool,
32 }
33
34 /// Create an iterator that interleaves elements in `i` and `j`.
35 ///
36 /// [`IntoIterator`] enabled version of [`Itertools::interleave`](crate::Itertools::interleave).
37 pub fn interleaverust-analyzer cargo itertools 0.14.0 adaptors/interleave().<I, J>(
38 i: I,
39 j: J,
40 ) -> Interleaverust-analyzer cargo itertools 0.14.0 adaptors/Interleave#<<I 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#, <J 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#>
41 where
42 I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#,
43 J: 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# = I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item#>,
44 {
45 Interleaverust-analyzer cargo itertools 0.14.0 adaptors/Interleave# {
46 irust-analyzer cargo itertools 0.14.0 adaptors/Interleave#i.: i.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().().fuserust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#fuse().(),
47 jrust-analyzer cargo itertools 0.14.0 adaptors/Interleave#j.: j.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().().fuserust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#fuse().(),
48 next_coming_from_jrust-analyzer cargo itertools 0.14.0 adaptors/Interleave#next_coming_from_j.: false,
49 }
50 }
51
52 impl<I, J> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Interleaverust-analyzer cargo itertools 0.14.0 adaptors/Interleave#<I, J>
53 where
54 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
55 J: 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#>,
56 {
57 type Itemrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Interleave<I, J>`][Iterator]Item# = I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#;
58 #[inline]
59 fn nextrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Interleave<I, J>`][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/impl#[`Interleave<I, J>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
60 self.next_coming_from_jrust-analyzer cargo itertools 0.14.0 adaptors/Interleave#next_coming_from_j. = !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.next_coming_from_jrust-analyzer cargo itertools 0.14.0 adaptors/Interleave#next_coming_from_j.;
61 if self.next_coming_from_jrust-analyzer cargo itertools 0.14.0 adaptors/Interleave#next_coming_from_j. {
62 match self.irust-analyzer cargo itertools 0.14.0 adaptors/Interleave#i..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]next().() {
63 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => self.jrust-analyzer cargo itertools 0.14.0 adaptors/Interleave#j..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]next().(),
64 r => r,
65 }
66 } else {
67 match self.jrust-analyzer cargo itertools 0.14.0 adaptors/Interleave#j..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]next().() {
68 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => self.irust-analyzer cargo itertools 0.14.0 adaptors/Interleave#i..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]next().(),
69 r => r,
70 }
71 }
72 }
73
74 fn size_hintrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Interleave<I, J>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
75 size_hintrust-analyzer cargo itertools 0.14.0 size_hint/::addrust-analyzer cargo itertools 0.14.0 size_hint/add().(self.irust-analyzer cargo itertools 0.14.0 adaptors/Interleave#i..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]size_hint().(), self.jrust-analyzer cargo itertools 0.14.0 adaptors/Interleave#j..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]size_hint().())
76 }
77
78 fn foldrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Interleave<I, J>`][Iterator]fold().<B, F>(self, mut init: B, mut f: F) -> B
79 where
80 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(B, Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Interleave<I, J>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> B,
81 {
82 let Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Interleave<I, J>`][Iterator] {
83 mut irust-analyzer cargo itertools 0.14.0 adaptors/Interleave#i.,
84 mut jrust-analyzer cargo itertools 0.14.0 adaptors/Interleave#j.,
85 next_coming_from_jrust-analyzer cargo itertools 0.14.0 adaptors/Interleave#next_coming_from_j.,
86 } = self;
87 if next_coming_from_j {
88 match j.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]next().() {
89 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(y) => init = f(init, y),
90 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return i.foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]fold().(init, f),
91 }
92 }
93 let res = i.try_foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]try_fold().(init, |mut acc, x| {
94 acc = f(acc, x);
95 match j.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]next().() {
96 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(y) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(f(acc, y)),
97 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(acc),
98 }
99 });
100 match res {
101 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(acc) => j.foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]fold().(acc, f),
102 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(acc) => i.foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]fold().(acc, f),
103 }
104 }
105 }
106
107 impl<I, J> FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for Interleaverust-analyzer cargo itertools 0.14.0 adaptors/Interleave#<I, J>
108 where
109 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
110 J: 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#>,
111 {
112 }
113
114 /// An iterator adaptor that alternates elements from the two iterators until
115 /// one of them runs out.
116 ///
117 /// This iterator is *fused*.
118 ///
119 /// See [`.interleave_shortest()`](crate::Itertools::interleave_shortest)
120 /// for more information.
121 #[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:)]
122 #[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
123 pub struct InterleaveShortestrust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#<I, J>
124 where
125 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
126 J: 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#>,
127 {
128 irust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#i.: I,
129 jrust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#j.: J,
130 next_coming_from_jrust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#next_coming_from_j.: bool,
131 }
132
133 /// Create a new `InterleaveShortest` iterator.
134 pub fn interleave_shortestrust-analyzer cargo itertools 0.14.0 adaptors/interleave_shortest().<I, J>(i: I, j: J) -> InterleaveShortestrust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#<I, J>
135 where
136 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
137 J: 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#>,
138 {
139 InterleaveShortestrust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest# {
140 irust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#i.,
141 jrust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#j.,
142 next_coming_from_jrust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#next_coming_from_j.: false,
143 }
144 }
145
146 impl<I, J> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for InterleaveShortestrust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#<I, J>
147 where
148 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
149 J: 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#>,
150 {
151 type Itemrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`InterleaveShortest<I, J>`][Iterator]Item# = I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#;
152
153 #[inline]
154 fn nextrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`InterleaveShortest<I, J>`][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/impl#[`InterleaveShortest<I, J>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
155 let e = if self.next_coming_from_jrust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#next_coming_from_j. {
156 self.jrust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#j..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().()
157 } else {
158 self.irust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#i..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().()
159 };
160 if e.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
161 self.next_coming_from_jrust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#next_coming_from_j. = !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.next_coming_from_jrust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#next_coming_from_j.;
162 }
163 e
164 }
165
166 #[inline]
167 fn size_hintrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`InterleaveShortest<I, J>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
168 let (curr_hint, next_hint) = {
169 let i_hint = self.irust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#i..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().();
170 let j_hint = self.jrust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#j..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().();
171 if self.next_coming_from_jrust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#next_coming_from_j. {
172 (j_hint, i_hint)
173 } else {
174 (i_hint, j_hint)
175 }
176 };
177 let (curr_lower, curr_upper) = curr_hint;
178 let (next_lower, next_upper) = next_hint;
179 let (combined_lower, combined_upper) =
180 size_hintrust-analyzer cargo itertools 0.14.0 size_hint/::mul_scalarrust-analyzer cargo itertools 0.14.0 size_hint/mul_scalar().(size_hintrust-analyzer cargo itertools 0.14.0 size_hint/::minrust-analyzer cargo itertools 0.14.0 size_hint/min().(curr_hint, next_hint), 2);
181 let lower = if curr_lower rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().next_lower {
182 combined_lower 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
183 } else {
184 combined_lower
185 };
186 let upper = {
187 let extra_elem = match (curr_upper, next_upper) {
188 (_, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => false,
189 (Nonerust-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#(_)) => true,
190 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(curr_max), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(next_max)) => curr_max rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().next_max,
191 };
192 if extra_elem {
193 combined_upper.and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|x| x.checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(1))
194 } else {
195 combined_upper
196 }
197 };
198 (lower, upper)
199 }
200
201 fn foldrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`InterleaveShortest<I, J>`][Iterator]fold().<B, F>(self, mut init: B, mut f: F) -> B
202 where
203 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(B, Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`InterleaveShortest<I, J>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> B,
204 {
205 let Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`InterleaveShortest<I, J>`][Iterator] {
206 mut irust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#i.,
207 mut jrust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#j.,
208 next_coming_from_jrust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#next_coming_from_j.,
209 } = self;
210 if next_coming_from_j {
211 match j.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() {
212 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(y) => init = f(init, y),
213 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return init,
214 }
215 }
216 let res = i.try_foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#try_fold().(init, |mut acc, x| {
217 acc = f(acc, x);
218 match j.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() {
219 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(y) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(f(acc, y)),
220 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(acc),
221 }
222 });
223 match res {
224 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(val) => val,
225 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(val) => val,
226 }
227 }
228 }
229
230 impl<I, J> FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for InterleaveShortestrust-analyzer cargo itertools 0.14.0 adaptors/InterleaveShortest#<I, J>
231 where
232 I: FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator#,
233 J: 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# = I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#>,
234 {
235 }
236
237 #[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:)]
238 /// An iterator adaptor that allows putting back a single
239 /// item to the front of the iterator.
240 ///
241 /// Iterator element type is `I::Item`.
242 #[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
243 pub struct PutBackrust-analyzer cargo itertools 0.14.0 adaptors/PutBack#<I>
244 where
245 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
246 {
247 toprust-analyzer cargo itertools 0.14.0 adaptors/PutBack#top.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#>,
248 iterrust-analyzer cargo itertools 0.14.0 adaptors/PutBack#iter.: I,
249 }
250
251 /// Create an iterator where you can put back a single item
252 pub fn put_backrust-analyzer cargo itertools 0.14.0 adaptors/put_back().<I>(iterable: I) -> PutBackrust-analyzer cargo itertools 0.14.0 adaptors/PutBack#<I::IntoIterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#IntoIter#>
253 where
254 I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#,
255 {
256 PutBackrust-analyzer cargo itertools 0.14.0 adaptors/PutBack# {
257 toprust-analyzer cargo itertools 0.14.0 adaptors/PutBack#top.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
258 iterrust-analyzer cargo itertools 0.14.0 adaptors/PutBack#iter.: iterable.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().(),
259 }
260 }
261
262 impl<I> PutBackrust-analyzer cargo itertools 0.14.0 adaptors/PutBack#<I>
263 where
264 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
265 {
266 /// put back value `value` (builder method)
267 pub fn with_valuerust-analyzer cargo itertools 0.14.0 adaptors/impl#[`PutBack<I>`]with_value().(mut self, value: I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`PutBack<I>`] {
268 self.put_backrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`PutBack<I>`]put_back().(value);
269 self
270 }
271
272 /// Split the `PutBack` into its parts.
273 #[inline]
274 pub fn into_partsrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`PutBack<I>`]into_parts().(self) -> (Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#>, I) {
275 let Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`PutBack<I>`] { toprust-analyzer cargo itertools 0.14.0 adaptors/PutBack#top., iterrust-analyzer cargo itertools 0.14.0 adaptors/PutBack#iter. } = self;
276 (top, iter)
277 }
278
279 /// Put back a single value to the front of the iterator.
280 ///
281 /// If a value is already in the put back slot, it is returned.
282 #[inline]
283 pub fn put_backrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`PutBack<I>`]put_back().(&mut self, x: I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
284 self.toprust-analyzer cargo itertools 0.14.0 adaptors/PutBack#top..replacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]replace().(x)
285 }
286 }
287
288 impl<I> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for PutBackrust-analyzer cargo itertools 0.14.0 adaptors/PutBack#<I>
289 where
290 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
291 {
292 type Itemrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`PutBack<I>`][Iterator]Item# = I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#;
293 #[inline]
294 fn nextrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`PutBack<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/impl#[`PutBack<I>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
295 match self.toprust-analyzer cargo itertools 0.14.0 adaptors/PutBack#top. {
296 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => self.iterrust-analyzer cargo itertools 0.14.0 adaptors/PutBack#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().(),
297 ref mut some => some.takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().(),
298 }
299 }
300 #[inline]
301 fn size_hintrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`PutBack<I>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
302 // Not ExactSizeIterator because size may be larger than usize
303 size_hintrust-analyzer cargo itertools 0.14.0 size_hint/::add_scalarrust-analyzer cargo itertools 0.14.0 size_hint/add_scalar().(self.iterrust-analyzer cargo itertools 0.14.0 adaptors/PutBack#iter..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().(), self.toprust-analyzer cargo itertools 0.14.0 adaptors/PutBack#top..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() as usize)
304 }
305
306 fn countrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`PutBack<I>`][Iterator]count().(self) -> usize {
307 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/PutBack#iter..countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().() 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().(self.toprust-analyzer cargo itertools 0.14.0 adaptors/PutBack#top..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() as usize)
308 }
309
310 fn lastrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`PutBack<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/impl#[`PutBack<I>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
311 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/PutBack#iter..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#last().().orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or().(self.toprust-analyzer cargo itertools 0.14.0 adaptors/PutBack#top.)
312 }
313
314 fn nthrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`PutBack<I>`][Iterator]nth().(&mut self, n: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`PutBack<I>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
315 match self.toprust-analyzer cargo itertools 0.14.0 adaptors/PutBack#top. {
316 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => self.iterrust-analyzer cargo itertools 0.14.0 adaptors/PutBack#iter..nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(n),
317 ref mut some => {
318 if n 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 {
319 some.takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().()
320 } else {
321 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().some = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
322 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/PutBack#iter..nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(n 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)
323 }
324 }
325 }
326 }
327
328 fn allrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`PutBack<I>`][Iterator]all().<G>(&mut self, mut f: G) -> bool
329 where
330 G: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`PutBack<I>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> bool,
331 {
332 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(elt) = self.toprust-analyzer cargo itertools 0.14.0 adaptors/PutBack#top..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() {
333 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().f(elt) {
334 return false;
335 }
336 }
337 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/PutBack#iter..allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(f)
338 }
339
340 fn foldrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`PutBack<I>`][Iterator]fold().<Acc, G>(mut self, init: Acc, mut f: G) -> Acc
341 where
342 G: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(Acc, Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`PutBack<I>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> Acc,
343 {
344 let mut accum = init;
345 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(elt) = self.toprust-analyzer cargo itertools 0.14.0 adaptors/PutBack#top..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() {
346 accum = f(accum, elt);
347 }
348 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/PutBack#iter..foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#fold().(accum, f)
349 }
350 }
351
352 #[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:)]
353 /// An iterator adaptor that iterates over the cartesian product of
354 /// the element sets of two iterators `I` and `J`.
355 ///
356 /// Iterator element type is `(I::Item, J::Item)`.
357 ///
358 /// See [`.cartesian_product()`](crate::Itertools::cartesian_product) for more information.
359 #[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
360 pub struct Productrust-analyzer cargo itertools 0.14.0 adaptors/Product#<I, J>
361 where
362 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
363 {
364 arust-analyzer cargo itertools 0.14.0 adaptors/Product#a.: I,
365 /// `a_cur` is `None` while no item have been taken out of `a` (at definition).
366 /// Then `a_cur` will be `Some(Some(item))` until `a` is exhausted,
367 /// in which case `a_cur` will be `Some(None)`.
368 a_currust-analyzer cargo itertools 0.14.0 adaptors/Product#a_cur.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#>>,
369 brust-analyzer cargo itertools 0.14.0 adaptors/Product#b.: J,
370 b_origrust-analyzer cargo itertools 0.14.0 adaptors/Product#b_orig.: J,
371 }
372
373 /// Create a new cartesian product iterator
374 ///
375 /// Iterator element type is `(I::Item, J::Item)`.
376 pub fn cartesian_productrust-analyzer cargo itertools 0.14.0 adaptors/cartesian_product().<I, J>(i: I, j: J) -> Productrust-analyzer cargo itertools 0.14.0 adaptors/Product#<I, J>
377 where
378 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
379 J: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
380 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#,
381 {
382 Productrust-analyzer cargo itertools 0.14.0 adaptors/Product# {
383 a_currust-analyzer cargo itertools 0.14.0 adaptors/Product#a_cur.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
384 arust-analyzer cargo itertools 0.14.0 adaptors/Product#a.: i,
385 brust-analyzer cargo itertools 0.14.0 adaptors/Product#b.: j.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(),
386 b_origrust-analyzer cargo itertools 0.14.0 adaptors/Product#b_orig.: j,
387 }
388 }
389
390 impl<I, J> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Productrust-analyzer cargo itertools 0.14.0 adaptors/Product#<I, J>
391 where
392 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
393 J: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
394 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#,
395 {
396 type Itemrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Product<I, J>`][Iterator]Item# = (I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#, J::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#);
397
398 fn nextrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Product<I, J>`][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/impl#[`Product<I, J>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
399 let Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Product<I, J>`][Iterator] {
400 arust-analyzer cargo itertools 0.14.0 adaptors/Product#a.,
401 a_currust-analyzer cargo itertools 0.14.0 adaptors/Product#a_cur.,
402 brust-analyzer cargo itertools 0.14.0 adaptors/Product#b.,
403 b_origrust-analyzer cargo itertools 0.14.0 adaptors/Product#b_orig.,
404 } = self;
405 let elt_b = match b.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() {
406 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
407 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().b = b_orig.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().();
408 match b.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() {
409 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
410 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(x) => {
411 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().a_cur = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(a.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().());
412 x
413 }
414 }
415 }
416 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(x) => x,
417 };
418 a_cur
419 .get_or_insert_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]get_or_insert_with().(|| a.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().())
420 .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()
421 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|a| (a.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), elt_b))
422 }
423
424 fn size_hintrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Product<I, J>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
425 // Not ExactSizeIterator because size may be larger than usize
426 // Compute a * b_orig + b for both lower and upper bound
427 let mut sh = size_hintrust-analyzer cargo itertools 0.14.0 size_hint/::mulrust-analyzer cargo itertools 0.14.0 size_hint/mul().(self.arust-analyzer cargo itertools 0.14.0 adaptors/Product#a..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().(), self.b_origrust-analyzer cargo itertools 0.14.0 adaptors/Product#b_orig..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().());
428 if matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self.a_currust-analyzer cargo itertools 0.14.0 adaptors/Product#a_cur., Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_))) {
429 sh = size_hintrust-analyzer cargo itertools 0.14.0 size_hint/::addrust-analyzer cargo itertools 0.14.0 size_hint/add().(sh, self.brust-analyzer cargo itertools 0.14.0 adaptors/Product#b..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().());
430 }
431 sh
432 }
433
434 fn foldrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Product<I, J>`][Iterator]fold().<Acc, G>(self, mut accum: Acc, mut f: G) -> Acc
435 where
436 G: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(Acc, Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Product<I, J>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> Acc,
437 {
438 // use a split loop to handle the loose a_cur as well as avoiding to
439 // clone b_orig at the end.
440 let Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Product<I, J>`][Iterator] {
441 mut arust-analyzer cargo itertools 0.14.0 adaptors/Product#a.,
442 a_currust-analyzer cargo itertools 0.14.0 adaptors/Product#a_cur.,
443 mut brust-analyzer cargo itertools 0.14.0 adaptors/Product#b.,
444 b_origrust-analyzer cargo itertools 0.14.0 adaptors/Product#b_orig.,
445 } = self;
446 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(mut elt_a) = a_cur.unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| a.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().()) {
447 loop {
448 accum = b.foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#fold().(accum, |acc, elt| f(acc, (elt_a.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), elt)));
449
450 // we can only continue iterating a if we had a first element;
451 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(next_elt_a) = a.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() {
452 b = b_orig.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().();
453 elt_a = next_elt_a;
454 } else {
455 break;
456 }
457 }
458 }
459 accum
460 }
461 }
462
463 impl<I, J> FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for Productrust-analyzer cargo itertools 0.14.0 adaptors/Product#<I, J>
464 where
465 I: FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator#,
466 J: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator#,
467 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#,
468 {
469 }
470
471 /// A “meta iterator adaptor”. Its closure receives a reference to the iterator
472 /// and may pick off as many elements as it likes, to produce the next iterator element.
473 ///
474 /// Iterator element type is `X` if the return type of `F` is `Option<X>`.
475 ///
476 /// See [`.batching()`](crate::Itertools::batching) for more information.
477 #[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:)]
478 #[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
479 pub struct Batchingrust-analyzer cargo itertools 0.14.0 adaptors/Batching#<I, F> {
480 frust-analyzer cargo itertools 0.14.0 adaptors/Batching#f.: F,
481 iterrust-analyzer cargo itertools 0.14.0 adaptors/Batching#iter.: I,
482 }
483
484 impl<I, F> 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 Batchingrust-analyzer cargo itertools 0.14.0 adaptors/Batching#<I, F>
485 where
486 I: 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#,
487 {
488 debug_fmt_fieldsrust-analyzer cargo itertools 0.14.0 impl_macros/debug_fmt_fields!!(Batching, iterrust-analyzer cargo itertools 0.14.0 adaptors/Batching#iter.);
489 }
490
491 /// Create a new Batching iterator.
492 pub fn batchingrust-analyzer cargo itertools 0.14.0 adaptors/batching().<I, F>(iter: I, f: F) -> Batchingrust-analyzer cargo itertools 0.14.0 adaptors/Batching#<I, F> {
493 Batchingrust-analyzer cargo itertools 0.14.0 adaptors/Batching# { frust-analyzer cargo itertools 0.14.0 adaptors/Batching#f., iterrust-analyzer cargo itertools 0.14.0 adaptors/Batching#iter. }
494 }
495
496 impl<B, F, I> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Batchingrust-analyzer cargo itertools 0.14.0 adaptors/Batching#<I, F>
497 where
498 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
499 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&mut I) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<B>,
500 {
501 type Itemrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Batching<I, F>`][Iterator]Item# = B;
502 #[inline]
503 fn nextrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Batching<I, F>`][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/impl#[`Batching<I, F>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
504 (self.frust-analyzer cargo itertools 0.14.0 adaptors/Batching#f.)(&mut self.iterrust-analyzer cargo itertools 0.14.0 adaptors/Batching#iter.)
505 }
506 }
507
508 /// An iterator adaptor that borrows from a `Clone`-able iterator
509 /// to only pick off elements while the predicate returns `true`.
510 ///
511 /// See [`.take_while_ref()`](crate::Itertools::take_while_ref) for more information.
512 #[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
513 pub struct TakeWhileRefrust-analyzer cargo itertools 0.14.0 adaptors/TakeWhileRef#<'a, I: 'a, F> {
514 iterrust-analyzer cargo itertools 0.14.0 adaptors/TakeWhileRef#iter.: &'a mut I,
515 frust-analyzer cargo itertools 0.14.0 adaptors/TakeWhileRef#f.: F,
516 }
517
518 impl<I, F> 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 TakeWhileRefrust-analyzer cargo itertools 0.14.0 adaptors/TakeWhileRef#<'_, I, F>
519 where
520 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# + 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#,
521 {
522 debug_fmt_fieldsrust-analyzer cargo itertools 0.14.0 impl_macros/debug_fmt_fields!!(TakeWhileRef, iterrust-analyzer cargo itertools 0.14.0 adaptors/TakeWhileRef#iter.);
523 }
524
525 /// Create a new `TakeWhileRef` from a reference to clonable iterator.
526 pub fn take_while_refrust-analyzer cargo itertools 0.14.0 adaptors/take_while_ref().<I, F>(iter: &mut I, f: F) -> TakeWhileRefrust-analyzer cargo itertools 0.14.0 adaptors/TakeWhileRef#<I, F>
527 where
528 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#,
529 {
530 TakeWhileRefrust-analyzer cargo itertools 0.14.0 adaptors/TakeWhileRef# { iterrust-analyzer cargo itertools 0.14.0 adaptors/TakeWhileRef#iter., frust-analyzer cargo itertools 0.14.0 adaptors/TakeWhileRef#f. }
531 }
532
533 impl<I, F> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for TakeWhileRefrust-analyzer cargo itertools 0.14.0 adaptors/TakeWhileRef#<'_, I, F>
534 where
535 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#,
536 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> bool,
537 {
538 type Itemrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`TakeWhileRef<'_, I, F>`][Iterator]Item# = I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#;
539
540 fn nextrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`TakeWhileRef<'_, I, F>`][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/impl#[`TakeWhileRef<'_, I, F>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
541 let old = self.iterrust-analyzer cargo itertools 0.14.0 adaptors/TakeWhileRef#iter..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().();
542 match self.iterrust-analyzer cargo itertools 0.14.0 adaptors/TakeWhileRef#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() {
543 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
544 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(elt) => {
545 if (self.frust-analyzer cargo itertools 0.14.0 adaptors/TakeWhileRef#f.)(&elt) {
546 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(elt)
547 } else {
548 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self.iterrust-analyzer cargo itertools 0.14.0 adaptors/TakeWhileRef#iter. = old;
549 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
550 }
551 }
552 }
553 }
554
555 fn size_hintrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`TakeWhileRef<'_, I, F>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
556 (0, self.iterrust-analyzer cargo itertools 0.14.0 adaptors/TakeWhileRef#iter..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/impl#[`&mut I`][Iterator]size_hint().().1)
557 }
558 }
559
560 /// An iterator adaptor that filters `Option<A>` iterator elements
561 /// and produces `A`. Stops on the first `None` encountered.
562 ///
563 /// See [`.while_some()`](crate::Itertools::while_some) for more information.
564 #[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:)]
565 #[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
566 pub struct WhileSomerust-analyzer cargo itertools 0.14.0 adaptors/WhileSome#<I> {
567 iterrust-analyzer cargo itertools 0.14.0 adaptors/WhileSome#iter.: I,
568 }
569
570 /// Create a new `WhileSome<I>`.
571 pub fn while_somerust-analyzer cargo itertools 0.14.0 adaptors/while_some().<I>(iter: I) -> WhileSomerust-analyzer cargo itertools 0.14.0 adaptors/WhileSome#<I> {
572 WhileSomerust-analyzer cargo itertools 0.14.0 adaptors/WhileSome# { iterrust-analyzer cargo itertools 0.14.0 adaptors/WhileSome#iter. }
573 }
574
575 impl<I, A> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for WhileSomerust-analyzer cargo itertools 0.14.0 adaptors/WhileSome#<I>
576 where
577 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# = Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<A>>,
578 {
579 type Itemrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`WhileSome<I>`][Iterator]Item# = A;
580
581 fn nextrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`WhileSome<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/impl#[`WhileSome<I>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
582 match self.iterrust-analyzer cargo itertools 0.14.0 adaptors/WhileSome#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() {
583 Nonerust-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#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
584 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(elt) => elt,
585 }
586 }
587
588 fn size_hintrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`WhileSome<I>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
589 (0, self.iterrust-analyzer cargo itertools 0.14.0 adaptors/WhileSome#iter..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().().1)
590 }
591
592 fn foldrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`WhileSome<I>`][Iterator]fold().<B, F>(mut self, acc: B, mut f: F) -> B
593 where
594 Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`WhileSome<I>`][Iterator]: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#,
595 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(B, Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`WhileSome<I>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> B,
596 {
597 let res = self.iterrust-analyzer cargo itertools 0.14.0 adaptors/WhileSome#iter..try_foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#try_fold().(acc, |acc, item| match item {
598 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(item) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(f(acc, item)),
599 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(acc),
600 });
601
602 match res {
603 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(val) => val,
604 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(val) => val,
605 }
606 }
607 }
608
609 /// An iterator to iterate through all combinations in a `Clone`-able iterator that produces tuples
610 /// of a specific size.
611 ///
612 /// See [`.tuple_combinations()`](crate::Itertools::tuple_combinations) for more
613 /// information.
614 #[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:)]
615 #[must_use = "this iterator adaptor is not lazy but does nearly nothing unless consumed"]
616 pub struct TupleCombinationsrust-analyzer cargo itertools 0.14.0 adaptors/TupleCombinations#<I, T>
617 where
618 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
619 T: HasCombinationrust-analyzer cargo itertools 0.14.0 adaptors/HasCombination#<I>,
620 {
621 iterrust-analyzer cargo itertools 0.14.0 adaptors/TupleCombinations#iter.: T::Combinationrust-analyzer cargo itertools 0.14.0 adaptors/HasCombination#Combination#,
622 _mirust-analyzer cargo itertools 0.14.0 adaptors/TupleCombinations#_mi.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<I>,
623 }
624
625 pub trait HasCombinationrust-analyzer cargo itertools 0.14.0 adaptors/HasCombination#<I>: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# {
626 type Combinationrust-analyzer cargo itertools 0.14.0 adaptors/HasCombination#Combination#: Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<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# = Self>;
627 }
628
629 /// Create a new `TupleCombinations` from a clonable iterator.
630 pub fn tuple_combinationsrust-analyzer cargo itertools 0.14.0 adaptors/tuple_combinations().<T, I>(iter: I) -> TupleCombinationsrust-analyzer cargo itertools 0.14.0 adaptors/TupleCombinations#<I, T>
631 where
632 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#,
633 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#,
634 T: HasCombinationrust-analyzer cargo itertools 0.14.0 adaptors/HasCombination#<I>,
635 {
636 TupleCombinationsrust-analyzer cargo itertools 0.14.0 adaptors/TupleCombinations# {
637 iterrust-analyzer cargo itertools 0.14.0 adaptors/TupleCombinations#iter.: T::Combinationrust-analyzer cargo itertools 0.14.0 adaptors/HasCombination#Combination#::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#from().(iter),
638 _mirust-analyzer cargo itertools 0.14.0 adaptors/TupleCombinations#_mi.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#,
639 }
640 }
641
642 impl<I, T> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for TupleCombinationsrust-analyzer cargo itertools 0.14.0 adaptors/TupleCombinations#<I, T>
643 where
644 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
645 T: HasCombinationrust-analyzer cargo itertools 0.14.0 adaptors/HasCombination#<I>,
646 {
647 type Itemrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`TupleCombinations<I, T>`][Iterator]Item# = T;
648
649 fn nextrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`TupleCombinations<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 adaptors/impl#[`TupleCombinations<I, T>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
650 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/TupleCombinations#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().()
651 }
652
653 fn size_hintrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`TupleCombinations<I, T>`][Iterator]size_hint().(&self) -> SizeHintrust-analyzer cargo itertools 0.14.0 size_hint/SizeHint# {
654 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/TupleCombinations#iter..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().()
655 }
656
657 fn countrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`TupleCombinations<I, T>`][Iterator]count().(self) -> usize {
658 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/TupleCombinations#iter..countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().()
659 }
660
661 fn foldrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`TupleCombinations<I, T>`][Iterator]fold().<B, F>(self, init: B, f: F) -> B
662 where
663 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(B, Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`TupleCombinations<I, T>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> B,
664 {
665 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/TupleCombinations#iter..foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#fold().(init, f)
666 }
667 }
668
669 impl<I, T> FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for TupleCombinationsrust-analyzer cargo itertools 0.14.0 adaptors/TupleCombinations#<I, T>
670 where
671 I: FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator#,
672 T: HasCombinationrust-analyzer cargo itertools 0.14.0 adaptors/HasCombination#<I>,
673 {
674 }
675
676 #[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:)]
677 pub struct Tuple1Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple1Combination#<I> {
678 iterrust-analyzer cargo itertools 0.14.0 adaptors/Tuple1Combination#iter.: I,
679 }
680
681 impl<I> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<I> for Tuple1Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple1Combination#<I> {
682 fn fromrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Tuple1Combination<I>`][`From<I>`]from().(iter: I) -> Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Tuple1Combination<I>`][`From<I>`] {
683 Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Tuple1Combination<I>`][`From<I>`] { iterrust-analyzer cargo itertools 0.14.0 adaptors/Tuple1Combination#iter. }
684 }
685 }
686
687 impl<I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Tuple1Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple1Combination#<I> {
688 type Itemrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Tuple1Combination<I>`][Iterator]Item# = (I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#,);
689
690 fn nextrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Tuple1Combination<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/impl#[`Tuple1Combination<I>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
691 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/Tuple1Combination#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|x| (x,))
692 }
693
694 fn size_hintrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Tuple1Combination<I>`][Iterator]size_hint().(&self) -> SizeHintrust-analyzer cargo itertools 0.14.0 size_hint/SizeHint# {
695 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/Tuple1Combination#iter..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().()
696 }
697
698 fn countrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Tuple1Combination<I>`][Iterator]count().(self) -> usize {
699 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/Tuple1Combination#iter..countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().()
700 }
701
702 fn foldrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Tuple1Combination<I>`][Iterator]fold().<B, F>(self, init: B, f: F) -> B
703 where
704 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(B, Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Tuple1Combination<I>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> B,
705 {
706 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/Tuple1Combination#iter..maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| (x,)).foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/map/impl#[`Map<I, F>`][Iterator]fold().(init, f)
707 }
708 }
709
710 impl<I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#> HasCombinationrust-analyzer cargo itertools 0.14.0 adaptors/HasCombination#<I> for (I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#,) {
711 type Combinationrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`(<I as Iterator>::Item,)`][`HasCombination<I>`]Combination# = Tuple1Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple1Combination#<I>;
712 }
713
714 macro_rules! impl_tuple_combinationrust-analyzer cargo itertools 0.14.0 adaptors/impl_tuple_combination! {
715 ($C:ident $P:ident ; $($X:ident)*) => (
716 #[derive(Clone, Debug)]
717 pub struct $C<I: Iterator> {
718 item: Option<I::Item>,
719 iter: I,
720 c: $P<I>,
721 }
722
723 impl<I: Iterator + Clone> From<I> for $C<I> {
724 fn from(mut iter: I) -> Self {
725 Self {
726 item: iter.next(),
727 iter: iter.clone(),
728 c: iter.into(),
729 }
730 }
731 }
732
733 impl<I: Iterator + Clone> From<I> for $C<Fuse<I>> {
734 fn from(iter: I) -> Self {
735 Self::from(iter.fuse())
736 }
737 }
738
739 impl<I, A> Iterator for $C<I>
740 where I: Iterator<Item = A> + Clone,
741 A: Clone,
742 {
743 type Item = (A, $(ignore_ident!($X, A)),*);
744
745 fn next(&mut self) -> Option<Self::Item> {
746 if let Some(($($X,)*)) = self.c.next() {
747 let z = self.item.clone().unwrap();
748 Some((z, $($X),*))
749 } else {
750 self.item = self.iter.next();
751 self.item.clone().and_then(|z| {
752 self.c = self.iter.clone().into();
753 self.c.next().map(|($($X,)*)| (z, $($X),*))
754 })
755 }
756 }
757
758 fn size_hint(&self) -> SizeHint {
759 const K: usize = 1 + count_ident!($($X)*);
760 let (mut n_min, mut n_max) = self.iter.size_hint();
761 n_min = checked_binomial(n_min, K).unwrap_or(usize::MAX);
762 n_max = n_max.and_then(|n| checked_binomial(n, K));
763 size_hint::add(self.c.size_hint(), (n_min, n_max))
764 }
765
766 fn count(self) -> usize {
767 const K: usize = 1 + count_ident!($($X)*);
768 let n = self.iter.count();
769 checked_binomial(n, K).unwrap() + self.c.count()
770 }
771
772 fn fold<B, F>(self, mut init: B, mut f: F) -> B
773 where
774 F: FnMut(B, Self::Item) -> B,
775 {
776 // We outline this closure to prevent it from unnecessarily
777 // capturing the type parameters `I`, `B`, and `F`. Not doing
778 // so ended up causing exponentially big types during MIR
779 // inlining when building itertools with optimizations enabled.
780 //
781 // This change causes a small improvement to compile times in
782 // release mode.
783 type CurrTuple<A> = (A, $(ignore_ident!($X, A)),*);
784 type PrevTuple<A> = ($(ignore_ident!($X, A),)*);
785 fn map_fn<A: Clone>(z: &A) -> impl FnMut(PrevTuple<A>) -> CurrTuple<A> + '_ {
786 move |($($X,)*)| (z.clone(), $($X),*)
787 }
788 let Self { c, item, mut iter } = self;
789 if let Some(z) = item.as_ref() {
790 init = c
791 .map(map_fn::<A>(z))
792 .fold(init, &mut f);
793 }
794 while let Some(z) = iter.next() {
795 let c: $P<I> = iter.clone().into();
796 init = c
797 .map(map_fn::<A>(&z))
798 .fold(init, &mut f);
799 }
800 init
801 }
802 }
803
804 impl<I, A> HasCombination<I> for (A, $(ignore_ident!($X, A)),*)
805 where I: Iterator<Item = A> + Clone,
806 I::Item: Clone
807 {
808 type Combination = $C<Fuse<I>>;
809 }
810 )
811 }
812
813 // This snippet generates the twelve `impl_tuple_combination!` invocations:
814 // use core::iter;
815 // use itertools::Itertools;
816 //
817 // for i in 2..=12 {
818 // println!("impl_tuple_combination!(Tuple{arity}Combination Tuple{prev}Combination; {idents});",
819 // arity = i,
820 // prev = i - 1,
821 // idents = ('a'..'z').take(i - 1).join(" "),
822 // );
823 // }
824 // It could probably be replaced by a bit more macro cleverness.
825 impl_tuple_combinationrust-analyzer cargo itertools 0.14.0 adaptors/impl_tuple_combination!!(Tuple2Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple2Combination# Tuple1Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple1Combination#; a);
826 impl_tuple_combinationrust-analyzer cargo itertools 0.14.0 adaptors/impl_tuple_combination!!(Tuple3Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple3Combination# Tuple2Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple2Combination#; a b);
827 impl_tuple_combinationrust-analyzer cargo itertools 0.14.0 adaptors/impl_tuple_combination!!(Tuple4Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple4Combination# Tuple3Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple3Combination#; a b c);
828 impl_tuple_combinationrust-analyzer cargo itertools 0.14.0 adaptors/impl_tuple_combination!!(Tuple5Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple5Combination# Tuple4Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple4Combination#; a b c d);
829 impl_tuple_combinationrust-analyzer cargo itertools 0.14.0 adaptors/impl_tuple_combination!!(Tuple6Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple6Combination# Tuple5Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple5Combination#; a b c d e);
830 impl_tuple_combinationrust-analyzer cargo itertools 0.14.0 adaptors/impl_tuple_combination!!(Tuple7Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple7Combination# Tuple6Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple6Combination#; a b c d e f);
831 impl_tuple_combinationrust-analyzer cargo itertools 0.14.0 adaptors/impl_tuple_combination!!(Tuple8Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple8Combination# Tuple7Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple7Combination#; a b c d e f g);
832 impl_tuple_combinationrust-analyzer cargo itertools 0.14.0 adaptors/impl_tuple_combination!!(Tuple9Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple9Combination# Tuple8Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple8Combination#; a b c d e f g h);
833 impl_tuple_combinationrust-analyzer cargo itertools 0.14.0 adaptors/impl_tuple_combination!!(Tuple10Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple10Combination# Tuple9Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple9Combination#; a b c d e f g h i);
834 impl_tuple_combinationrust-analyzer cargo itertools 0.14.0 adaptors/impl_tuple_combination!!(Tuple11Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple11Combination# Tuple10Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple10Combination#; a b c d e f g h i j);
835 impl_tuple_combinationrust-analyzer cargo itertools 0.14.0 adaptors/impl_tuple_combination!!(Tuple12Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple12Combination# Tuple11Combinationrust-analyzer cargo itertools 0.14.0 adaptors/Tuple11Combination#; a b c d e f g h i j k);
836
837 // https://en.wikipedia.org/wiki/Binomial_coefficient#In_programming_languages
838 pub(craterust-analyzer cargo itertools 0.14.0 crate/) fn checked_binomialrust-analyzer cargo itertools 0.14.0 adaptors/checked_binomial().(mut n: usize, mut k: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize> {
839 if n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().k {
840 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0);
841 }
842 // `factorial(n) / factorial(n - k) / factorial(k)` but trying to avoid it overflows:
843 k = (n 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().k).minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#min().(k); // symmetry
844 let mut c = 1;
845 for i in 1..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#k {
846 c = (c 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().i)
847 .checked_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_mul().(n)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().
848 .checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().((c 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().i).checked_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_mul().(n)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch(). 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().i)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
849 n 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;
850 }
851 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c)
852 }
853
854 #[test]
855 fn test_checked_binomial() {
856 // With the first row: [1, 0, 0, ...] and the first column full of 1s, we check
857 // row by row the recurrence relation of binomials (which is an equivalent definition).
858 // For n >= 1 and k >= 1 we have:
859 // binomial(n, k) == binomial(n - 1, k - 1) + binomial(n - 1, k)
860 const LIMIT: usize = 500;
861 let mut row = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Some(0); LIMIT + 1];
862 row[0] = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1);
863 for n in 0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#LIMIT {
864 for k in 0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#LIMIT {
865 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(row[k], checked_binomial(n, k));
866 }
867 row = 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().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1))
868 .chain((1..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#LIMIT).map(|k| row[k - 1]?.checked_add(row[k]?)))
869 .collect();
870 }
871 }
872
873 /// An iterator adapter to filter values within a nested `Result::Ok`.
874 ///
875 /// See [`.filter_ok()`](crate::Itertools::filter_ok) for more information.
876 #[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:)]
877 #[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
878 pub struct FilterOkrust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#<I, F> {
879 iterrust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#iter.: I,
880 frust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#f.: F,
881 }
882
883 impl<I, F> 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 FilterOkrust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#<I, F>
884 where
885 I: 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#,
886 {
887 debug_fmt_fieldsrust-analyzer cargo itertools 0.14.0 impl_macros/debug_fmt_fields!!(FilterOk, iterrust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#iter.);
888 }
889
890 /// Create a new `FilterOk` iterator.
891 pub fn filter_okrust-analyzer cargo itertools 0.14.0 adaptors/filter_ok().<I, F, T, E>(iter: I, f: F) -> FilterOkrust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#<I, F>
892 where
893 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# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>>,
894 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&T) -> bool,
895 {
896 FilterOkrust-analyzer cargo itertools 0.14.0 adaptors/FilterOk# { iterrust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#iter., frust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#f. }
897 }
898
899 impl<I, F, T, E> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for FilterOkrust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#<I, F>
900 where
901 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# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>>,
902 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&T) -> bool,
903 {
904 type Itemrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterOk<I, F>`][Iterator]Item# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>;
905
906 fn nextrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterOk<I, F>`][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/impl#[`FilterOk<I, F>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
907 let f = &mut self.frust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#f.;
908 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#iter..findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|res| match res {
909 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(t) => f(t),
910 _ => true,
911 })
912 }
913
914 fn size_hintrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterOk<I, F>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
915 (0, self.iterrust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#iter..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().().1)
916 }
917
918 fn foldrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterOk<I, F>`][Iterator]fold().<Acc, Fold>(self, init: Acc, fold_f: Fold) -> Acc
919 where
920 Fold: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(Acc, Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterOk<I, F>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> Acc,
921 {
922 let mut f = self.frust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#f.;
923 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#iter.
924 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|v| v.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]as_ref().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(&mut f).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(true))
925 .foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]fold().(init, fold_f)
926 }
927
928 fn collectrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterOk<I, F>`][Iterator]collect().<C>(self) -> C
929 where
930 C: FromIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/FromIterator#<Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterOk<I, F>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#>,
931 {
932 let mut f = self.frust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#f.;
933 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#iter.
934 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|v| v.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]as_ref().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(&mut f).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(true))
935 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()
936 }
937 }
938
939 impl<I, F, T, E> DoubleEndedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator# for FilterOkrust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#<I, F>
940 where
941 I: DoubleEndedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>>,
942 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&T) -> bool,
943 {
944 fn next_backrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterOk<I, F>`][DoubleEndedIterator]next_back().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterOk<I, F>`][DoubleEndedIterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
945 let f = &mut self.frust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#f.;
946 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#iter..rfindrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator#rfind().(|res| match res {
947 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(t) => f(t),
948 _ => true,
949 })
950 }
951
952 fn rfoldrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterOk<I, F>`][DoubleEndedIterator]rfold().<Acc, Fold>(self, init: Acc, fold_f: Fold) -> Acc
953 where
954 Fold: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(Acc, Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterOk<I, F>`][DoubleEndedIterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> Acc,
955 {
956 let mut f = self.frust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#f.;
957 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#iter.
958 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|v| v.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]as_ref().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(&mut f).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(true))
959 .rfoldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][DoubleEndedIterator]rfold().(init, fold_f)
960 }
961 }
962
963 impl<I, F, T, E> FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for FilterOkrust-analyzer cargo itertools 0.14.0 adaptors/FilterOk#<I, F>
964 where
965 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# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>>,
966 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&T) -> bool,
967 {
968 }
969
970 /// An iterator adapter to filter and apply a transformation on values within a nested `Result::Ok`.
971 ///
972 /// See [`.filter_map_ok()`](crate::Itertools::filter_map_ok) for more information.
973 #[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
974 #[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:)]
975 pub struct FilterMapOkrust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#<I, F> {
976 iterrust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#iter.: I,
977 frust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#f.: F,
978 }
979
980 impl<I, F> 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 FilterMapOkrust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#<I, F>
981 where
982 I: 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#,
983 {
984 debug_fmt_fieldsrust-analyzer cargo itertools 0.14.0 impl_macros/debug_fmt_fields!!(FilterMapOk, iterrust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#iter.);
985 }
986
987 fn transpose_resultrust-analyzer cargo itertools 0.14.0 adaptors/transpose_result().<T, E>(result: Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T>, E>) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>> {
988 match result {
989 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v)) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(v)),
990 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
991 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e)),
992 }
993 }
994
995 /// Create a new `FilterOk` iterator.
996 pub fn filter_map_okrust-analyzer cargo itertools 0.14.0 adaptors/filter_map_ok().<I, F, T, U, E>(iter: I, f: F) -> FilterMapOkrust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#<I, F>
997 where
998 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# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>>,
999 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(T) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<U>,
1000 {
1001 FilterMapOkrust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk# { iterrust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#iter., frust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#f. }
1002 }
1003
1004 impl<I, F, T, U, E> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for FilterMapOkrust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#<I, F>
1005 where
1006 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# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>>,
1007 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(T) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<U>,
1008 {
1009 type Itemrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterMapOk<I, F>`][Iterator]Item# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<U, E>;
1010
1011 fn nextrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterMapOk<I, F>`][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/impl#[`FilterMapOk<I, F>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
1012 let f = &mut self.frust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#f.;
1013 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#iter..find_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find_map().(|res| match res {
1014 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(t) => f(t).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#),
1015 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e)),
1016 })
1017 }
1018
1019 fn size_hintrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterMapOk<I, F>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
1020 (0, self.iterrust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#iter..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().().1)
1021 }
1022
1023 fn foldrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterMapOk<I, F>`][Iterator]fold().<Acc, Fold>(self, init: Acc, fold_f: Fold) -> Acc
1024 where
1025 Fold: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(Acc, Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterMapOk<I, F>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> Acc,
1026 {
1027 let mut f = self.frust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#f.;
1028 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#iter.
1029 .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|v| transpose_resultrust-analyzer cargo itertools 0.14.0 adaptors/transpose_result().(v.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(&mut f)))
1030 .foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]fold().(init, fold_f)
1031 }
1032
1033 fn collectrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterMapOk<I, F>`][Iterator]collect().<C>(self) -> C
1034 where
1035 C: FromIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/FromIterator#<Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterMapOk<I, F>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#>,
1036 {
1037 let mut f = self.frust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#f.;
1038 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#iter.
1039 .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|v| transpose_resultrust-analyzer cargo itertools 0.14.0 adaptors/transpose_result().(v.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(&mut f)))
1040 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()
1041 }
1042 }
1043
1044 impl<I, F, T, U, E> DoubleEndedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator# for FilterMapOkrust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#<I, F>
1045 where
1046 I: DoubleEndedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>>,
1047 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(T) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<U>,
1048 {
1049 fn next_backrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterMapOk<I, F>`][DoubleEndedIterator]next_back().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterMapOk<I, F>`][DoubleEndedIterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
1050 let f = &mut self.frust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#f.;
1051 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#iter..by_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#by_ref().().revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().().find_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find_map().(|res| match res {
1052 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(t) => f(t).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#),
1053 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e)),
1054 })
1055 }
1056
1057 fn rfoldrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterMapOk<I, F>`][DoubleEndedIterator]rfold().<Acc, Fold>(self, init: Acc, fold_f: Fold) -> Acc
1058 where
1059 Fold: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(Acc, Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`FilterMapOk<I, F>`][DoubleEndedIterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> Acc,
1060 {
1061 let mut f = self.frust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#f.;
1062 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#iter.
1063 .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|v| transpose_resultrust-analyzer cargo itertools 0.14.0 adaptors/transpose_result().(v.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(&mut f)))
1064 .rfoldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][DoubleEndedIterator]rfold().(init, fold_f)
1065 }
1066 }
1067
1068 impl<I, F, T, U, E> FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for FilterMapOkrust-analyzer cargo itertools 0.14.0 adaptors/FilterMapOk#<I, F>
1069 where
1070 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# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>>,
1071 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(T) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<U>,
1072 {
1073 }
1074
1075 /// An iterator adapter to get the positions of each element that matches a predicate.
1076 ///
1077 /// See [`.positions()`](crate::Itertools::positions) for more information.
1078 #[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:)]
1079 #[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
1080 pub struct Positionsrust-analyzer cargo itertools 0.14.0 adaptors/Positions#<I, F> {
1081 iterrust-analyzer cargo itertools 0.14.0 adaptors/Positions#iter.: Enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/enumerate/Enumerate#<I>,
1082 frust-analyzer cargo itertools 0.14.0 adaptors/Positions#f.: F,
1083 }
1084
1085 impl<I, F> 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 Positionsrust-analyzer cargo itertools 0.14.0 adaptors/Positions#<I, F>
1086 where
1087 I: 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#,
1088 {
1089 debug_fmt_fieldsrust-analyzer cargo itertools 0.14.0 impl_macros/debug_fmt_fields!!(Positions, iterrust-analyzer cargo itertools 0.14.0 adaptors/Positions#iter.);
1090 }
1091
1092 /// Create a new `Positions` iterator.
1093 pub fn positionsrust-analyzer cargo itertools 0.14.0 adaptors/positions().<I, F>(iter: I, f: F) -> Positionsrust-analyzer cargo itertools 0.14.0 adaptors/Positions#<I, F>
1094 where
1095 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
1096 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> bool,
1097 {
1098 let iter = iter.enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().();
1099 Positionsrust-analyzer cargo itertools 0.14.0 adaptors/Positions# { iterrust-analyzer cargo itertools 0.14.0 adaptors/Positions#iter., frust-analyzer cargo itertools 0.14.0 adaptors/Positions#f. }
1100 }
1101
1102 impl<I, F> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Positionsrust-analyzer cargo itertools 0.14.0 adaptors/Positions#<I, F>
1103 where
1104 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
1105 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> bool,
1106 {
1107 type Itemrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Positions<I, F>`][Iterator]Item# = usize;
1108
1109 fn nextrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Positions<I, F>`][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/impl#[`Positions<I, F>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
1110 let f = &mut self.frust-analyzer cargo itertools 0.14.0 adaptors/Positions#f.;
1111 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/Positions#iter..find_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find_map().(|(count, val)| f(val).then_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then_some().(count))
1112 }
1113
1114 fn size_hintrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Positions<I, F>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
1115 (0, self.iterrust-analyzer cargo itertools 0.14.0 adaptors/Positions#iter..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/enumerate/impl#[`Enumerate<I>`][Iterator]size_hint().().1)
1116 }
1117
1118 fn foldrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Positions<I, F>`][Iterator]fold().<B, G>(self, init: B, mut func: G) -> B
1119 where
1120 G: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(B, Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Positions<I, F>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> B,
1121 {
1122 let mut f = self.frust-analyzer cargo itertools 0.14.0 adaptors/Positions#f.;
1123 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/Positions#iter..foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/enumerate/impl#[`Enumerate<I>`][Iterator]fold().(init, |mut acc, (count, val)| {
1124 if f(val) {
1125 acc = func(acc, count);
1126 }
1127 acc
1128 })
1129 }
1130 }
1131
1132 impl<I, F> DoubleEndedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator# for Positionsrust-analyzer cargo itertools 0.14.0 adaptors/Positions#<I, F>
1133 where
1134 I: DoubleEndedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator# + ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#,
1135 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> bool,
1136 {
1137 fn next_backrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Positions<I, F>`][DoubleEndedIterator]next_back().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Positions<I, F>`][DoubleEndedIterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
1138 let f = &mut self.frust-analyzer cargo itertools 0.14.0 adaptors/Positions#f.;
1139 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/Positions#iter.
1140 .by_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#by_ref().()
1141 .revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().()
1142 .find_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find_map().(|(count, val)| f(val).then_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then_some().(count))
1143 }
1144
1145 fn rfoldrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Positions<I, F>`][DoubleEndedIterator]rfold().<B, G>(self, init: B, mut func: G) -> B
1146 where
1147 G: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(B, Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Positions<I, F>`][DoubleEndedIterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> B,
1148 {
1149 let mut f = self.frust-analyzer cargo itertools 0.14.0 adaptors/Positions#f.;
1150 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/Positions#iter..rfoldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/enumerate/impl#[`Enumerate<I>`][DoubleEndedIterator]rfold().(init, |mut acc, (count, val)| {
1151 if f(val) {
1152 acc = func(acc, count);
1153 }
1154 acc
1155 })
1156 }
1157 }
1158
1159 impl<I, F> FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for Positionsrust-analyzer cargo itertools 0.14.0 adaptors/Positions#<I, F>
1160 where
1161 I: FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator#,
1162 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> bool,
1163 {
1164 }
1165
1166 /// An iterator adapter to apply a mutating function to each element before yielding it.
1167 ///
1168 /// See [`.update()`](crate::Itertools::update) for more information.
1169 #[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:)]
1170 #[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
1171 pub struct Updaterust-analyzer cargo itertools 0.14.0 adaptors/Update#<I, F> {
1172 iterrust-analyzer cargo itertools 0.14.0 adaptors/Update#iter.: I,
1173 frust-analyzer cargo itertools 0.14.0 adaptors/Update#f.: F,
1174 }
1175
1176 impl<I, F> 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 Updaterust-analyzer cargo itertools 0.14.0 adaptors/Update#<I, F>
1177 where
1178 I: 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#,
1179 {
1180 debug_fmt_fieldsrust-analyzer cargo itertools 0.14.0 impl_macros/debug_fmt_fields!!(Update, iterrust-analyzer cargo itertools 0.14.0 adaptors/Update#iter.);
1181 }
1182
1183 /// Create a new `Update` iterator.
1184 pub fn updaterust-analyzer cargo itertools 0.14.0 adaptors/update().<I, F>(iter: I, f: F) -> Updaterust-analyzer cargo itertools 0.14.0 adaptors/Update#<I, F>
1185 where
1186 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
1187 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&mut I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#),
1188 {
1189 Updaterust-analyzer cargo itertools 0.14.0 adaptors/Update# { iterrust-analyzer cargo itertools 0.14.0 adaptors/Update#iter., frust-analyzer cargo itertools 0.14.0 adaptors/Update#f. }
1190 }
1191
1192 impl<I, F> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Updaterust-analyzer cargo itertools 0.14.0 adaptors/Update#<I, F>
1193 where
1194 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
1195 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&mut I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#),
1196 {
1197 type Itemrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Update<I, F>`][Iterator]Item# = I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#;
1198
1199 fn nextrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Update<I, F>`][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/impl#[`Update<I, F>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
1200 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(mut v) = self.iterrust-analyzer cargo itertools 0.14.0 adaptors/Update#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() {
1201 (self.frust-analyzer cargo itertools 0.14.0 adaptors/Update#f.)(&mut v);
1202 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v)
1203 } else {
1204 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
1205 }
1206 }
1207
1208 fn size_hintrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Update<I, F>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
1209 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/Update#iter..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().()
1210 }
1211
1212 fn foldrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Update<I, F>`][Iterator]fold().<Acc, G>(self, init: Acc, mut g: G) -> Acc
1213 where
1214 G: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(Acc, Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Update<I, F>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> Acc,
1215 {
1216 let mut f = self.frust-analyzer cargo itertools 0.14.0 adaptors/Update#f.;
1217 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/Update#iter..foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#fold().(init, move |acc, mut v| {
1218 f(&mut v);
1219 g(acc, v)
1220 })
1221 }
1222
1223 // if possible, re-use inner iterator specializations in collect
1224 fn collectrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Update<I, F>`][Iterator]collect().<C>(self) -> C
1225 where
1226 C: FromIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/FromIterator#<Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Update<I, F>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#>,
1227 {
1228 let mut f = self.frust-analyzer cargo itertools 0.14.0 adaptors/Update#f.;
1229 self.iterrust-analyzer cargo itertools 0.14.0 adaptors/Update#iter.
1230 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(move |mut v| {
1231 f(&mut v);
1232 v
1233 })
1234 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()
1235 }
1236 }
1237
1238 impl<I, F> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for Updaterust-analyzer cargo itertools 0.14.0 adaptors/Update#<I, F>
1239 where
1240 I: ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#,
1241 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&mut I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#),
1242 {
1243 }
1244
1245 impl<I, F> DoubleEndedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator# for Updaterust-analyzer cargo itertools 0.14.0 adaptors/Update#<I, F>
1246 where
1247 I: DoubleEndedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator#,
1248 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&mut I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#),
1249 {
1250 fn next_backrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Update<I, F>`][DoubleEndedIterator]next_back().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo itertools 0.14.0 adaptors/impl#[`Update<I, F>`][DoubleEndedIterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
1251 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(mut v) = self.iterrust-analyzer cargo itertools 0.14.0 adaptors/Update#iter..next_backrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator#next_back().() {
1252 (self.frust-analyzer cargo itertools 0.14.0 adaptors/Update#f.)(&mut v);
1253 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v)
1254 } else {
1255 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
1256 }
1257 }
1258 }
1259
1260 impl<I, F> FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for Updaterust-analyzer cargo itertools 0.14.0 adaptors/Update#<I, F>
1261 where
1262 I: FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator#,
1263 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&mut I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#),
1264 {
1265 }