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

Allow immutable iter on Queries which contain mutable references #753

Closed
alec-deason opened this issue Oct 31, 2020 · 1 comment
Closed
Labels
A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change C-Usability A simple quality-of-life change that makes Bevy easier to use
Milestone

Comments

@alec-deason
Copy link
Member

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.

@alec-deason alec-deason added the C-Enhancement A new feature label Oct 31, 2020
@karroffel karroffel added the A-ECS Entities, components, systems, and events label Oct 31, 2020
@alice-i-cecile alice-i-cecile added C-Usability A simple quality-of-life change that makes Bevy easier to use C-Code-Quality A section of code that is hard to understand or change and removed C-Enhancement A new feature labels Feb 17, 2021
@pcwalton
Copy link
Contributor

#2744 is an example of where the lack of this breaks integration with the most popular Rust physics library.

@cart cart added this to the Bevy 0.6 milestone Aug 30, 2021
@bors bors bot closed this as completed in 274ace7 Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change C-Usability A simple quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants