@@ -10,30 +10,24 @@ use std::iter::{self, Zip};
10
10
type VecIntoIter < T > = alloc:: vec:: IntoIter < T > ;
11
11
12
12
#[ cfg( feature = "use_alloc" ) ]
13
- use alloc:: {
14
- string:: String ,
15
- } ;
13
+ use alloc:: string:: String ;
16
14
17
- use crate :: Itertools ;
18
15
use crate :: intersperse:: { Intersperse , IntersperseWith } ;
16
+ use crate :: Itertools ;
19
17
20
- pub use crate :: adaptors:: {
21
- interleave,
22
- merge,
23
- put_back,
24
- } ;
18
+ pub use crate :: adaptors:: { interleave, merge, put_back} ;
25
19
#[ cfg( feature = "use_alloc" ) ]
26
- pub use crate :: put_back_n_impl:: put_back_n;
20
+ pub use crate :: kmerge_impl:: kmerge;
21
+ pub use crate :: merge_join:: merge_join_by;
27
22
#[ cfg( feature = "use_alloc" ) ]
28
23
pub use crate :: multipeek_impl:: multipeek;
29
24
#[ cfg( feature = "use_alloc" ) ]
30
25
pub use crate :: peek_nth:: peek_nth;
31
26
#[ cfg( feature = "use_alloc" ) ]
32
- pub use crate :: kmerge_impl:: kmerge;
33
- pub use crate :: zip_eq_impl:: zip_eq;
34
- pub use crate :: merge_join:: merge_join_by;
27
+ pub use crate :: put_back_n_impl:: put_back_n;
35
28
#[ cfg( feature = "use_alloc" ) ]
36
29
pub use crate :: rciter_impl:: rciter;
30
+ pub use crate :: zip_eq_impl:: zip_eq;
37
31
38
32
/// Iterate `iterable` with a particular value inserted between each element.
39
33
///
@@ -45,8 +39,9 @@ pub use crate::rciter_impl::rciter;
45
39
/// itertools::assert_equal(intersperse((0..3), 8), vec![0, 8, 1, 8, 2]);
46
40
/// ```
47
41
pub fn intersperse < I > ( iterable : I , element : I :: Item ) -> Intersperse < I :: IntoIter >
48
- where I : IntoIterator ,
49
- <I as IntoIterator >:: Item : Clone
42
+ where
43
+ I : IntoIterator ,
44
+ <I as IntoIterator >:: Item : Clone ,
50
45
{
51
46
Itertools :: intersperse ( iterable. into_iter ( ) , element)
52
47
}
@@ -64,8 +59,9 @@ pub fn intersperse<I>(iterable: I, element: I::Item) -> Intersperse<I::IntoIter>
64
59
/// assert_eq!(i, 8);
65
60
/// ```
66
61
pub fn intersperse_with < I , F > ( iterable : I , element : F ) -> IntersperseWith < I :: IntoIter , F >
67
- where I : IntoIterator ,
68
- F : FnMut ( ) -> I :: Item
62
+ where
63
+ I : IntoIterator ,
64
+ F : FnMut ( ) -> I :: Item ,
69
65
{
70
66
Itertools :: intersperse_with ( iterable. into_iter ( ) , element)
71
67
}
@@ -82,7 +78,8 @@ pub fn intersperse_with<I, F>(iterable: I, element: F) -> IntersperseWith<I::Int
82
78
/// }
83
79
/// ```
84
80
pub fn enumerate < I > ( iterable : I ) -> iter:: Enumerate < I :: IntoIter >
85
- where I : IntoIterator
81
+ where
82
+ I : IntoIterator ,
86
83
{
87
84
iterable. into_iter ( ) . enumerate ( )
88
85
}
@@ -99,8 +96,9 @@ pub fn enumerate<I>(iterable: I) -> iter::Enumerate<I::IntoIter>
99
96
/// }
100
97
/// ```
101
98
pub fn rev < I > ( iterable : I ) -> iter:: Rev < I :: IntoIter >
102
- where I : IntoIterator ,
103
- I :: IntoIter : DoubleEndedIterator
99
+ where
100
+ I : IntoIterator ,
101
+ I :: IntoIter : DoubleEndedIterator ,
104
102
{
105
103
iterable. into_iter ( ) . rev ( )
106
104
}
@@ -112,14 +110,20 @@ pub fn rev<I>(iterable: I) -> iter::Rev<I::IntoIter>
112
110
/// ```
113
111
/// use itertools::zip;
114
112
///
115
- /// let data = [1, 2, 3, 4, 5];
116
- /// for (a, b) in zip(&data, &data[1..]) {
117
- /// /* loop body */
113
+ /// let data_1 = [1, 2, 3, 4, 5];
114
+ /// let data_2 = ['a', 'b', 'c'];
115
+ /// let mut result: Vec<(i32, char)> = Vec::new();
116
+ ///
117
+ /// for (a, b) in zip(&data_1, &data_2) {
118
+ /// result.push((*a, *b));
118
119
/// }
120
+ /// assert_eq!(result, vec![(1, 'a'),(2, 'b'),(3, 'c')]);
119
121
/// ```
122
+ ///
120
123
pub fn zip < I , J > ( i : I , j : J ) -> Zip < I :: IntoIter , J :: IntoIter >
121
- where I : IntoIterator ,
122
- J : IntoIterator
124
+ where
125
+ I : IntoIterator ,
126
+ J : IntoIterator ,
123
127
{
124
128
i. into_iter ( ) . zip ( j)
125
129
}
@@ -135,9 +139,13 @@ pub fn zip<I, J>(i: I, j: J) -> Zip<I::IntoIter, J::IntoIter>
135
139
/// /* loop body */
136
140
/// }
137
141
/// ```
138
- pub fn chain < I , J > ( i : I , j : J ) -> iter:: Chain < <I as IntoIterator >:: IntoIter , <J as IntoIterator >:: IntoIter >
139
- where I : IntoIterator ,
140
- J : IntoIterator < Item = I :: Item >
142
+ pub fn chain < I , J > (
143
+ i : I ,
144
+ j : J ,
145
+ ) -> iter:: Chain < <I as IntoIterator >:: IntoIter , <J as IntoIterator >:: IntoIter >
146
+ where
147
+ I : IntoIterator ,
148
+ J : IntoIterator < Item = I :: Item > ,
141
149
{
142
150
i. into_iter ( ) . chain ( j)
143
151
}
@@ -152,8 +160,9 @@ pub fn chain<I, J>(i: I, j: J) -> iter::Chain<<I as IntoIterator>::IntoIter, <J
152
160
/// assert_eq!(cloned(b"abc").next(), Some(b'a'));
153
161
/// ```
154
162
pub fn cloned < ' a , I , T : ' a > ( iterable : I ) -> iter:: Cloned < I :: IntoIter >
155
- where I : IntoIterator < Item =& ' a T > ,
156
- T : Clone ,
163
+ where
164
+ I : IntoIterator < Item = & ' a T > ,
165
+ T : Clone ,
157
166
{
158
167
iterable. into_iter ( ) . cloned ( )
159
168
}
@@ -168,8 +177,9 @@ pub fn cloned<'a, I, T: 'a>(iterable: I) -> iter::Cloned<I::IntoIter>
168
177
/// assert_eq!(fold(&[1., 2., 3.], 0., |a, &b| f32::max(a, b)), 3.);
169
178
/// ```
170
179
pub fn fold < I , B , F > ( iterable : I , init : B , f : F ) -> B
171
- where I : IntoIterator ,
172
- F : FnMut ( B , I :: Item ) -> B
180
+ where
181
+ I : IntoIterator ,
182
+ F : FnMut ( B , I :: Item ) -> B ,
173
183
{
174
184
iterable. into_iter ( ) . fold ( init, f)
175
185
}
@@ -184,8 +194,9 @@ pub fn fold<I, B, F>(iterable: I, init: B, f: F) -> B
184
194
/// assert!(all(&[1, 2, 3], |elt| *elt > 0));
185
195
/// ```
186
196
pub fn all < I , F > ( iterable : I , f : F ) -> bool
187
- where I : IntoIterator ,
188
- F : FnMut ( I :: Item ) -> bool
197
+ where
198
+ I : IntoIterator ,
199
+ F : FnMut ( I :: Item ) -> bool ,
189
200
{
190
201
iterable. into_iter ( ) . all ( f)
191
202
}
@@ -200,8 +211,9 @@ pub fn all<I, F>(iterable: I, f: F) -> bool
200
211
/// assert!(any(&[0, -1, 2], |elt| *elt > 0));
201
212
/// ```
202
213
pub fn any < I , F > ( iterable : I , f : F ) -> bool
203
- where I : IntoIterator ,
204
- F : FnMut ( I :: Item ) -> bool
214
+ where
215
+ I : IntoIterator ,
216
+ F : FnMut ( I :: Item ) -> bool ,
205
217
{
206
218
iterable. into_iter ( ) . any ( f)
207
219
}
@@ -216,8 +228,9 @@ pub fn any<I, F>(iterable: I, f: F) -> bool
216
228
/// assert_eq!(max(0..10), Some(9));
217
229
/// ```
218
230
pub fn max < I > ( iterable : I ) -> Option < I :: Item >
219
- where I : IntoIterator ,
220
- I :: Item : Ord
231
+ where
232
+ I : IntoIterator ,
233
+ I :: Item : Ord ,
221
234
{
222
235
iterable. into_iter ( ) . max ( )
223
236
}
@@ -232,13 +245,13 @@ pub fn max<I>(iterable: I) -> Option<I::Item>
232
245
/// assert_eq!(min(0..10), Some(0));
233
246
/// ```
234
247
pub fn min < I > ( iterable : I ) -> Option < I :: Item >
235
- where I : IntoIterator ,
236
- I :: Item : Ord
248
+ where
249
+ I : IntoIterator ,
250
+ I :: Item : Ord ,
237
251
{
238
252
iterable. into_iter ( ) . min ( )
239
253
}
240
254
241
-
242
255
/// Combine all iterator elements into one String, separated by `sep`.
243
256
///
244
257
/// [`IntoIterator`] enabled version of [`Itertools::join`].
@@ -250,8 +263,9 @@ pub fn min<I>(iterable: I) -> Option<I::Item>
250
263
/// ```
251
264
#[ cfg( feature = "use_alloc" ) ]
252
265
pub fn join < I > ( iterable : I , sep : & str ) -> String
253
- where I : IntoIterator ,
254
- I :: Item : Display
266
+ where
267
+ I : IntoIterator ,
268
+ I :: Item : Display ,
255
269
{
256
270
iterable. into_iter ( ) . join ( sep)
257
271
}
@@ -268,9 +282,9 @@ pub fn join<I>(iterable: I, sep: &str) -> String
268
282
/// ```
269
283
#[ cfg( feature = "use_alloc" ) ]
270
284
pub fn sorted < I > ( iterable : I ) -> VecIntoIter < I :: Item >
271
- where I : IntoIterator ,
272
- I :: Item : Ord
285
+ where
286
+ I : IntoIterator ,
287
+ I :: Item : Ord ,
273
288
{
274
289
iterable. into_iter ( ) . sorted ( )
275
290
}
276
-
0 commit comments