Skip to content

Allow immutable iter on Queries which contain mutable references #753

Closed
@alec-deason

Description

@alec-deason

What problem does this solve or what need does it fill?

The new Query api follows rust conventions by using .iter() to create iterators over queries of immutable component references and .iter_mut() to create iterators over queries of mutable component references. However, it deviates from rust convention by not allowing iter() to be called on queries of mutable component references.

Describe the solution would you like?

I expect .iter() on a mutable iterable object to return an iterator of immutable references rather than fail with a compilation error. That would make the API consistent with other similar APIs in rust and allow programmers to signal clearly where they are iterating over a query which is used mutably elsewhere in the system but is being used immutable at the moment.

Describe the alternative(s) you've considered?

I have yet to encounter a case where calling iter_mut is a serious problem, so keeping the existing API is certainly an alternative.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-Code-QualityA section of code that is hard to understand or changeC-UsabilityA targeted quality-of-life change that makes Bevy easier to use

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions