diff options
| author | William Chargin <wchargin@gmail.com> | 2020-11-23 11:59:42 -0800 |
|---|---|---|
| committer | William Chargin <wchargin@gmail.com> | 2020-11-23 11:59:42 -0800 |
| commit | ce3d60476a9f307e71c2928ab575cfced6831187 (patch) | |
| tree | db7faf4380398de67ed473d119b05a2d2dd8df76 /compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp | |
| parent | 40cf72108edb9b8633a9d284b238988309204494 (diff) | |
| download | rust-ce3d60476a9f307e71c2928ab575cfced6831187.tar.gz rust-ce3d60476a9f307e71c2928ab575cfced6831187.zip | |
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.
Implementation note: I haven’t linkified the references to `HashSet` and
`HashMap`, since those are in `std` and these docs are in `core`;
linkifying them gave an “unresolved link” rustdoc error.
Test Plan:
Ran `./x.py doc library/core`, and the result looked good. Manually
copy-pasted the two doctests into the playground and ran them.
wchargin-branch: doc-iter-by-reference
wchargin-source: 0f35369a8a735868621166608797744e97536792
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
