File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -130,6 +130,22 @@ pub trait Stream {
130130
131131 /// Transforms a stream into a collection.
132132 ///
133+ /// `collect()` can take anything streamable, and turn it into a relevant
134+ /// collection. This is one of the more powerful methods in the async
135+ /// standard library, used in a variety of contexts.
136+ ///
137+ /// The most basic pattern in which `collect()` is used is to turn one
138+ /// collection into another. You take a collection, call [`stream`] on it,
139+ /// do a bunch of transformations, and then `collect()` at the end.
140+ ///
141+ /// Because `collect()` is so general, it can cause problems with type
142+ /// inference. As such, `collect()` is one of the few times you'll see
143+ /// the syntax affectionately known as the 'turbofish': `::<>`. This
144+ /// helps the inference algorithm understand specifically which collection
145+ /// you're trying to collect into.
146+ ///
147+ /// # Examples
148+ ///
133149 /// ```
134150 /// # fn main() { async_std::task::block_on(async {
135151 /// #
@@ -143,6 +159,8 @@ pub trait Stream {
143159 /// #
144160 /// # }) }
145161 /// ```
162+ ///
163+ /// [`stream`]: trait.Stream.html#tymethod.next
146164 #[ must_use = "if you really need to exhaust the iterator, consider `.for_each(drop)` instead (TODO)" ]
147165 fn collect < ' a , B : FromStream < <Self as Stream >:: Item > > ( self ) -> dyn_ret ! ( ' a, B )
148166 where
You can’t perform that action at this time.
0 commit comments