|
16 | 16 | //! exist and what you can do with them. The methods of these traits are worth
|
17 | 17 | //! putting some extra study time into.
|
18 | 18 | //! * Functions provide some helpful ways to create some basic streams.
|
19 |
| -//! * [Structs] are often the return types of the various methods on this |
| 19 | +//! * Structs are often the return types of the various methods on this |
20 | 20 | //! module's traits. You'll usually want to look at the method that creates
|
21 | 21 | //! the `struct`, rather than the `struct` itself. For more detail about why,
|
22 | 22 | //! see '[Implementing Stream](#implementing-stream)'.
|
23 | 23 | //!
|
24 | 24 | //! [Traits]: #traits
|
25 |
| -//! [Structs]: #structs |
26 | 25 | //!
|
27 | 26 | //! That's it! Let's dig into streams.
|
28 | 27 | //!
|
|
41 | 40 | //! ```
|
42 | 41 | //!
|
43 | 42 | //! Unlike `Iterator`, `Stream` makes a distinction between the [`poll_next`]
|
44 |
| -//! method which is used when implementing a `Stream`, and the [`next`] method |
45 |
| -//! which is used when consuming a stream. Consumers of `Stream` only need to |
46 |
| -//! consider [`next`], which when called, returns a future which yields |
47 |
| -//! yields [`Option`][`<Item>`]. |
| 43 | +//! method which is used when implementing a `Stream`, and a (to-be-implemented) |
| 44 | +//! `next` method which is used when consuming a stream. Consumers of `Stream` |
| 45 | +//! only need to consider `next`, which when called, returns a future which |
| 46 | +//! yields `Option<Stream::Item>`. |
48 | 47 | //!
|
49 |
| -//! The future returned by [`next`] will yield `Some(Item)` as long as there are |
| 48 | +//! The future returned by `next` will yield `Some(Item)` as long as there are |
50 | 49 | //! elements, and once they've all been exhausted, will yield `None` to indicate
|
51 | 50 | //! that iteration is finished. If we're waiting on something asynchronous to
|
52 | 51 | //! resolve, the future will wait until the stream is ready to yield again.
|
53 | 52 | //!
|
54 |
| -//! Individual streams may choose to resume iteration, and so calling [`next`] |
| 53 | +//! Individual streams may choose to resume iteration, and so calling `next` |
55 | 54 | //! again may or may not eventually yield `Some(Item)` again at some point.
|
56 | 55 | //!
|
57 | 56 | //! [`Stream`]'s full definition includes a number of other methods as well,
|
|
60 | 59 | //!
|
61 | 60 | //! [`Poll`]: super::task::Poll
|
62 | 61 | //! [`poll_next`]: Stream::poll_next
|
63 |
| -//! [`next`]: Stream::next |
64 |
| -//! [`<Item>`]: Stream::Item |
65 | 62 | //!
|
66 | 63 | //! # Implementing Stream
|
67 | 64 | //!
|
|
112 | 109 | //! }
|
113 | 110 | //! }
|
114 | 111 | //! }
|
115 |
| -//! |
116 |
| -//! // And now we can use it! |
117 |
| -//! # async fn run() { |
118 |
| -//! # |
119 |
| -//! let mut counter = Counter::new(); |
120 |
| -//! |
121 |
| -//! let x = counter.next().await.unwrap(); |
122 |
| -//! println!("{}", x); |
123 |
| -//! |
124 |
| -//! let x = counter.next().await.unwrap(); |
125 |
| -//! println!("{}", x); |
126 |
| -//! |
127 |
| -//! let x = counter.next().await.unwrap(); |
128 |
| -//! println!("{}", x); |
129 |
| -//! |
130 |
| -//! let x = counter.next().await.unwrap(); |
131 |
| -//! println!("{}", x); |
132 |
| -//! |
133 |
| -//! let x = counter.next().await.unwrap(); |
134 |
| -//! println!("{}", x); |
135 |
| -//! # |
136 |
| -//! } |
137 | 112 | //! ```
|
138 | 113 | //!
|
139 |
| -//! This will print `1` through `5`, each on their own line. |
140 |
| -//! |
141 | 114 | //! # Laziness
|
142 | 115 | //!
|
143 | 116 | //! Streams are *lazy*. This means that just creating a stream doesn't _do_ a
|
144 |
| -//! whole lot. Nothing really happens until you call [`next`]. This is sometimes a |
| 117 | +//! whole lot. Nothing really happens until you call `next`. This is sometimes a |
145 | 118 | //! source of confusion when creating a stream solely for its side effects. The
|
146 | 119 | //! compiler will warn us about this kind of behavior:
|
147 | 120 | //!
|
|
151 | 124 |
|
152 | 125 | mod stream;
|
153 | 126 |
|
154 |
| -pub use stream::{Next, Stream}; |
| 127 | +pub use stream::Stream; |
0 commit comments