Added Query::for_each_combinations(_mut)
, Updated Query::for_each(_mut)
#9546
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Also updated function signatures of
Query::for_each(_mut)
to use a more restrictive lifetime on their borrows. This is a breaking change, but I believe it is the more "correct" API only recently made possible.I also don't believe this breaking change is significant, as I don't believe there are any circumstances where you would need to escape a borrow out of a closure inside a
for_each
statement.iter().map(...)
should provide all the required functionality in those cases anyway.Objective
Solution
Query::for_each_combinations
andQuery::for_each_combinations_mut
with appropriate documentation.Query::for_each
andQuery::for_each_mut
to use closure-specific lifetime throughfor<'item>
Changelog
Query::for_each
andQuery::for_each_mut
provide references to their closures that no longer have the same lifetime as&self
, and instead only last as long as the execution of the closure through the use offor<'item>
. This is a breaking change.Migration Guide
Code which used
Query::for_each
orQuery::for_each_mut
to borrow data from a query should instead useQuery::iter
orQuery::iter_mut
with.map(...)
to achieve the same result. In practice, I don't believe there are many instances where this breaking change would actually affect real projects, as it appears to be a poor way to borrow data from aQuery
.