Skip to content

The iter_many_mut documentation is confused #5506

Description

@nicopap

Calls a closure on each result of Query where the entities match.

The documentation talks about calling a "closure", but iter_many_mut doesn't have a closure argument, as the example shows. https://docs.rs/bevy/latest/bevy/ecs/system/struct.Query.html#method.iter_many_mut

Activity

  1. added
    C-DocsAn addition or correction to our documentation
    A-ECSEntities, components, systems, and events
    on Jul 31, 2022
  2. Nilirad commented on Jul 31, 2022

    @Nilirad
    Contributor

    I'll rebase #4989 to main and add more appropriate doc comments.

  3. self-assigned this
    on Jul 31, 2022
  4. ian-h-chamberlain commented on Aug 28, 2022

    @ian-h-chamberlain
    Contributor

    To add to this, it would be helpful to add a mention that the returned value is not actually an Iterator. I was confused by the errors when I tried

    for foo in q.iter_many_mut(&entities) {}

    The comment on the Iterator impl for QueryManyIter explains this a bit:

    /// Iterator type is intentionally implemented only for read-only access.
    /// Doing so for mutable references would be unsound,
    /// because calling `next` multiple times would allow multiple owned references to the same data to exist.
    

    but it might be good to mention as well on iter_many_mut as well, to explain the need for this usage (which can easily be misread as the more common while let Some(_) = it.next():

    let mut it = q.iter_many_mut(&entities)
    while let Some(foo) = it.fetch_next() {}
  5. added 2 commits that reference this issue on Sep 2, 2022
    47ecff4
    dfeb63e
  6. added a commit that references this issue on Oct 28, 2022
    ceff825
  7. added a commit that references this issue on Feb 1, 2023
    df93083
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-ECSEntities, components, systems, and eventsC-DocsAn addition or correction to our documentation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions