Allow World::entity
family of functions to take multiple entities and get multiple references back
#15614
+793
−472
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.
Objective
Following the pattern established in #15593, we can reduce the API surface of
World
by providing a single function to grab both a singular entity reference, or multiple entity references.Solution
The following functions can now also take multiple entity IDs and will return multiple entity references back:
World::entity
World::get_entity
World::entity_mut
World::get_entity_mut
DeferredWorld::entity_mut
DeferredWorld::get_entity_mut
If you pass in X, you receive Y:
Entity
, receive a singleEntityRef
/EntityWorldMut
(matches current behavior)[Entity; N]
/&[Entity; N]
(array), receive an equally-sized[EntityRef; N]
/[EntityMut; N]
&[Entity]
(slice), receive aVec<EntityRef>
/Vec<EntityMut>
&EntityHashSet
, receive aEntityHashMap<EntityRef>
/EntityHashMap<EntityMut>
Note that
EntityWorldMut
is only returned in the single-entity case, because having multiple at the same time would lead to UB. Also,DeferredWorld
receives anEntityMut
in the single-entity case because it does not allow structural access.Testing
World::entity
,World::entity_mut
, andDeferredWorld::entity_mut
Showcase
While a showcase should aim to be brief and digestible, you can use a toggleable section to save space on longer showcases:
Click to view showcase
Migration Guide