File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -244,6 +244,20 @@ pub trait IteratorExt: Iterator + Sized {
244
244
/// assert_eq!(it.next().unwrap(), (&0, &1));
245
245
/// assert!(it.next().is_none());
246
246
/// ```
247
+ ///
248
+ /// `zip` can provide similar functionality to `enumerate`:
249
+ ///
250
+ /// ```
251
+ /// for pair in "foo".chars().enumerate() {
252
+ /// println!("{:?}", pair);
253
+ /// }
254
+ ///
255
+ /// for pair in (0..).zip("foo".chars()) {
256
+ /// println!("{:?}", pair);
257
+ /// }
258
+ /// ```
259
+ ///
260
+ /// both produce the same output.
247
261
#[ inline]
248
262
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
249
263
fn zip < U : Iterator > ( self , other : U ) -> Zip < Self , U > {
@@ -313,6 +327,9 @@ pub trait IteratorExt: Iterator + Sized {
313
327
/// Creates an iterator that yields a pair of the value returned by this
314
328
/// iterator plus the current index of iteration.
315
329
///
330
+ /// `enumerate` keeps its count as a `usize`. If you want to count by a
331
+ /// different sized integer, the `zip` function provides similar functionality.
332
+ ///
316
333
/// # Examples
317
334
///
318
335
/// ```
You can’t perform that action at this time.
0 commit comments