Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::iter: document iteration over &T and &mut T #79360

Merged
merged 2 commits into from
Dec 13, 2020

Commits on Nov 23, 2020

  1. 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
    wchargin committed Nov 23, 2020
    Configuration menu
    Copy the full SHA
    ce3d604 View commit details
    Browse the repository at this point in the history
  2. [update patch]

    wchargin-branch: doc-iter-by-reference
    wchargin-source: e4069ac9a9d73860467cea74cf3ae1605af37d74
    wchargin committed Nov 23, 2020
    Configuration menu
    Copy the full SHA
    6edc90a View commit details
    Browse the repository at this point in the history