-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add many_entities_mut function variants to DeferredWorld
#15067
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
Conversation
chescock
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's nice to have a little more API consistency between the various World variants! I like how you were able to share more code between the mut and non-mut versions by putting common code in UnsafeWorldCell.
| entities: [Entity; N], | ||
| ) -> Result<[EntityMut<'_>; N], QueryEntityError> { | ||
| let world_cell = self.as_unsafe_world_cell(); | ||
| // SAFETY: The `world_cell` has exclusive access to the entire world, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _mut methods on World look the same as the ones on DeferredWorld. Could you share the implementation by doing something like DeferredWorld::from(self).get_many_entities_mut();? (Or maybe there is a simpler way to get from &mut World to DeferredWorld?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DeferredWorld::from(self).get_many_entities_mut();
This doesn't work unfortunately:
error[E0515]: cannot return value referencing temporary value
--> crates\bevy_ecs\src\world\mod.rs:766:9
|
766 | DeferredWorld::from(self).get_many_entities_mut(entities)
| -------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| returns a value referencing data owned by the current function
| temporary value created here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see, &mut DeferredWorld is only a borrow of a borrow. To make that work, you'd need DeferredWorld.get_many_entities_mut() to take self by value so that it can return values with the 'w lifetime, but then you'd need to call .reborrow() almost every time you use it.
| assert!(world | ||
| .get_many_entities_from_set_mut(&EntityHashSet::from_iter([entity1, entity2])) | ||
| .is_ok()); | ||
| assert!(world |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have an assertion to a error of non-existent entity? Entity::PLACEHOLDER is probably useful for this.
|
Closed in favor of #15614 |
Objective
Closes #15038.
Solution
Added:
DeferredWorld::get_many_entities_mutDeferredWorld::many_entities_mutDeferredWorld::get_many_entities_dynamic_mutDeferredWorld::get_many_entities_from_set_mutUnsafeWorldCell::get_entities(used by the above functions)UnsafeWorldCell::get_entities_dynamic(used by the above functions)Changed:
Worldreuse the newly introduced methods onUnsafeWorldCellfor their implementations.DeferredWorld::get_entity_mut.Testing
Worldfunctions since they were previously missing.DeferredWorldfunctions.Migration Guide
World::get_many_entitiesandWorld::get_many_entities_dynamicnow returnQueryEntityErrorinstead ofEntityin theErrpath to match the signatures of their_mutcounterparts.