Skip to content

Commit ea14ce5

Browse files
authored
Rollup merge of #150743 - docs/iterator, r=Mark-Simulacrum
Reword the collect() docs Update the `Iterator::collect` docs so they explain that the return type, not the iterator itself, determines which collection is built. Follow up on #121140
2 parents 7a9ef99 + 139d59f commit ea14ce5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

‎library/core/src/iter/traits/iterator.rs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,9 +1906,12 @@ pub trait Iterator {
19061906

19071907
/// Transforms an iterator into a collection.
19081908
///
1909-
/// `collect()` can take anything iterable, and turn it into a relevant
1910-
/// collection. This is one of the more powerful methods in the standard
1911-
/// library, used in a variety of contexts.
1909+
/// `collect()` takes ownership of an iterator and produces whichever
1910+
/// collection type you request. The iterator itself carries no knowledge of
1911+
/// the eventual container; the target collection is chosen entirely by the
1912+
/// type you ask `collect()` to return. This makes `collect()` one of the
1913+
/// more powerful methods in the standard library, and it shows up in a wide
1914+
/// variety of contexts.
19121915
///
19131916
/// The most basic pattern in which `collect()` is used is to turn one
19141917
/// collection into another. You take a collection, call [`iter`] on it,

0 commit comments

Comments
 (0)