Skip to content

Commit b1c0758

Browse files
committed
collect docs
Signed-off-by: Yoshua Wuyts <[email protected]>
1 parent 9f0cbd8 commit b1c0758

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/stream/stream.rs

+18
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)