rust/library/core/src/iter
Yuki Okushi 1698773263
Rollup merge of #79360 - wchargin:wchargin-doc-iter-by-reference, r=m-ou-se
std::iter: document iteration over `&T` and `&mut T`

A colleague of mine is new to Rust, and mentioned that it was “slightly
confusing” to figure out what `&mut` does in iterating over `&mut foo`:

```rust
for value in &mut self.my_vec {
    // ...
}
```

My colleague had read the `std::iter` docs and not found the answer
there. There is a brief section at the top about “the three forms of
iteration”, which mentions `iter_mut`, but it doesn’t cover the purpose
of `&mut coll` for a collection `coll`. This patch adds an explanatory
section to the docs. I opted to create a new section so that it can
appear after the note that `impl<I: Iterator> IntoIterator for I`, and
it’s nice for the existing “three forms of iteration” to appear near the
top.

Test Plan:
Ran `./x.py doc library/core`, and the result looked good, including
links. Manually copy-pasted the two doctests into the playground and ran
them.

wchargin-branch: doc-iter-by-reference
2020-12-13 11:05:22 +09:00
..
adapters Intra doc links for iterator adapters 2020-11-30 21:18:55 +01:00
sources Remove multiline uses 2020-11-22 02:39:22 +03:00
traits Improve wording of flatten() docs 2020-12-10 20:36:12 -08:00
mod.rs [update patch] 2020-11-23 15:46:13 -08:00
range.rs Use try{} in try_fold to decouple library from Try details 2020-10-12 16:17:12 -07:00
sources.rs Split iterator sources into different modules 2020-11-22 02:39:21 +03:00