Skip to content

Commit 8111d65

Browse files
committed
Rollup merge of rust-lang#22293 - steveklabnik:gh12891, r=brson
Fixes rust-lang#12891.
2 parents ed58399 + 6647d83 commit 8111d65

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/doc/trpl/iterators.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,16 @@ let one_to_one_hundred = (1..101i32).collect::<Vec<i32>>();
132132
```
133133

134134
If you remember, the `::<>` syntax allows us to give a type hint,
135-
and so we tell it that we want a vector of integers.
135+
and so we tell it that we want a vector of integers. You don't always
136+
need to use the whole type, though. Using a `_` will let you provide
137+
a partial hint:
138+
139+
```rust
140+
let one_to_one_hundred = range(1, 101).collect::<Vec<_>>();
141+
```
142+
143+
This says "Collect into a `Vec<T>`, please, but infer what the `T` is for me."
144+
`_` is sometimes called a "type placeholder" for this reason.
136145

137146
`collect()` is the most common consumer, but there are others too. `find()`
138147
is one:

0 commit comments

Comments
 (0)