Add into_world_mut to EntityMut (#5586)
# Objective Provide a safe API to access an `EntityMut`'s `World`. ## Solution * Add `EntityMut::into_world_mut` for safe access to the entity's world. --- ## Changelog * Add `EntityMut::into_world_mut` for safe access to the entity's world.
This commit is contained in:
parent
a9634c7344
commit
397b6df023
@ -495,15 +495,25 @@ impl<'w> EntityMut<'w> {
|
|||||||
self.world
|
self.world
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns this `EntityMut`'s world.
|
||||||
|
///
|
||||||
|
/// See [`EntityMut::into_world_mut`] for a safe alternative.
|
||||||
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// Caller must not modify the world in a way that changes the current entity's location
|
/// Caller must not modify the world in a way that changes the current entity's location
|
||||||
/// If the caller _does_ do something that could change the location, `self.update_location()`
|
/// If the caller _does_ do something that could change the location, `self.update_location()`
|
||||||
/// must be called before using any other methods in [`EntityMut`]
|
/// must be called before using any other methods on this [`EntityMut`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn world_mut(&mut self) -> &mut World {
|
pub unsafe fn world_mut(&mut self) -> &mut World {
|
||||||
self.world
|
self.world
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return this `EntityMut`'s [`World`], consuming itself.
|
||||||
|
#[inline]
|
||||||
|
pub fn into_world_mut(self) -> &'w mut World {
|
||||||
|
self.world
|
||||||
|
}
|
||||||
|
|
||||||
/// Updates the internal entity location to match the current location in the internal
|
/// Updates the internal entity location to match the current location in the internal
|
||||||
/// [`World`]. This is only needed if the user called [`EntityMut::world`], which enables the
|
/// [`World`]. This is only needed if the user called [`EntityMut::world`], which enables the
|
||||||
/// location to change.
|
/// location to change.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user