|
8 | 8 | // option. This file may not be copied, modified, or distributed |
9 | 9 | // except according to those terms. |
10 | 10 |
|
11 | | -/*! |
12 | | -
|
13 | | -Composable external iterators |
14 | | -
|
15 | | -# The `Iterator` trait |
16 | | -
|
17 | | -This module defines Rust's core iteration trait. The `Iterator` trait has one |
18 | | -unimplemented method, `next`. All other methods are derived through default |
19 | | -methods to perform operations such as `zip`, `chain`, `enumerate`, and `fold`. |
20 | | -
|
21 | | -The goal of this module is to unify iteration across all containers in Rust. |
22 | | -An iterator can be considered as a state machine which is used to track which |
23 | | -element will be yielded next. |
24 | | -
|
25 | | -There are various extensions also defined in this module to assist with various |
26 | | -types of iteration, such as the `DoubleEndedIterator` for iterating in reverse, |
27 | | -the `FromIterator` trait for creating a container from an iterator, and much |
28 | | -more. |
29 | | -
|
30 | | -## Rust's `for` loop |
31 | | -
|
32 | | -The special syntax used by rust's `for` loop is based around the `Iterator` |
33 | | -trait defined in this module. For loops can be viewed as a syntactical expansion |
34 | | -into a `loop`, for example, the `for` loop in this example is essentially |
35 | | -translated to the `loop` below. |
36 | | -
|
37 | | -```rust |
38 | | -let values = vec![1i, 2, 3]; |
39 | | -
|
40 | | -// "Syntactical sugar" taking advantage of an iterator |
41 | | -for &x in values.iter() { |
42 | | - println!("{}", x); |
43 | | -} |
44 | | -
|
45 | | -// Rough translation of the iteration without a `for` iterator. |
46 | | -let mut it = values.iter(); |
47 | | -loop { |
48 | | - match it.next() { |
49 | | - Some(&x) => { |
50 | | - println!("{}", x); |
51 | | - } |
52 | | - None => { break } |
53 | | - } |
54 | | -} |
55 | | -``` |
56 | | -
|
57 | | -This `for` loop syntax can be applied to any iterator over any type. |
58 | | -
|
59 | | -*/ |
| 11 | +//! Composable external iterators |
| 12 | +//! |
| 13 | +//! # The `Iterator` trait |
| 14 | +//! |
| 15 | +//! This module defines Rust's core iteration trait. The `Iterator` trait has one |
| 16 | +//! unimplemented method, `next`. All other methods are derived through default |
| 17 | +//! methods to perform operations such as `zip`, `chain`, `enumerate`, and `fold`. |
| 18 | +//! |
| 19 | +//! The goal of this module is to unify iteration across all containers in Rust. |
| 20 | +//! An iterator can be considered as a state machine which is used to track which |
| 21 | +//! element will be yielded next. |
| 22 | +//! |
| 23 | +//! There are various extensions also defined in this module to assist with various |
| 24 | +//! types of iteration, such as the `DoubleEndedIterator` for iterating in reverse, |
| 25 | +//! the `FromIterator` trait for creating a container from an iterator, and much |
| 26 | +//! more. |
| 27 | +//! |
| 28 | +//! ## Rust's `for` loop |
| 29 | +//! |
| 30 | +//! The special syntax used by rust's `for` loop is based around the `Iterator` |
| 31 | +//! trait defined in this module. For loops can be viewed as a syntactical expansion |
| 32 | +//! into a `loop`, for example, the `for` loop in this example is essentially |
| 33 | +//! translated to the `loop` below. |
| 34 | +//! |
| 35 | +//! ```rust |
| 36 | +//! let values = vec![1i, 2, 3]; |
| 37 | +//! |
| 38 | +//! // "Syntactical sugar" taking advantage of an iterator |
| 39 | +//! for &x in values.iter() { |
| 40 | +//! println!("{}", x); |
| 41 | +//! } |
| 42 | +//! |
| 43 | +//! // Rough translation of the iteration without a `for` iterator. |
| 44 | +//! let mut it = values.iter(); |
| 45 | +//! loop { |
| 46 | +//! match it.next() { |
| 47 | +//! Some(&x) => { |
| 48 | +//! println!("{}", x); |
| 49 | +//! } |
| 50 | +//! None => { break } |
| 51 | +//! } |
| 52 | +//! } |
| 53 | +//! ``` |
| 54 | +//! |
| 55 | +//! This `for` loop syntax can be applied to any iterator over any type. |
60 | 56 |
|
61 | 57 | pub use self::MinMaxResult::*; |
62 | 58 |
|
|
0 commit comments