Skip to content

Commit

Permalink
Add into_world_mut to EntityMut (bevyengine#5586)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
nicopap authored and james7132 committed Oct 28, 2022
1 parent 370bbca commit 28cef96
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crates/bevy_ecs/src/world/entity_ref.rs
Expand Up @@ -495,15 +495,25 @@ impl<'w> EntityMut<'w> {
self.world
}

/// Returns this `EntityMut`'s world.
///
/// See [`EntityMut::into_world_mut`] for a safe alternative.
///
/// # Safety
/// 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()`
/// must be called before using any other methods in [`EntityMut`]
/// must be called before using any other methods on this [`EntityMut`].
#[inline]
pub unsafe fn world_mut(&mut self) -> &mut 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
/// [`World`]. This is only needed if the user called [`EntityMut::world`], which enables the
/// location to change.
Expand Down

0 comments on commit 28cef96

Please sign in to comment.