From ce6889b9a8d75b89c00d2600d789b0148171750a Mon Sep 17 00:00:00 2001 From: TheRawMeatball Date: Wed, 5 May 2021 19:35:07 +0000 Subject: [PATCH] Implement direct mutable dereferencing (#2100) This PR adds a way to get the underlying mutable reference for it's full lifetime. Context: https://discord.com/channels/691052431525675048/692572690833473578/839255317287796796 --- crates/bevy_ecs/src/world/pointer.rs | 7 +++++++ crates/bevy_ecs/src/world/world_cell.rs | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/world/pointer.rs b/crates/bevy_ecs/src/world/pointer.rs index c7add3a58f..695b2eb750 100644 --- a/crates/bevy_ecs/src/world/pointer.rs +++ b/crates/bevy_ecs/src/world/pointer.rs @@ -9,6 +9,13 @@ pub struct Mut<'a, T> { pub(crate) change_tick: u32, } +impl<'a, T> Mut<'a, T> { + pub fn into_inner(self) -> &'a mut T { + self.component_ticks.set_changed(self.change_tick); + self.value + } +} + impl<'a, T> Deref for Mut<'a, T> { type Target = T; diff --git a/crates/bevy_ecs/src/world/world_cell.rs b/crates/bevy_ecs/src/world/world_cell.rs index 11aee9fd40..e128167d56 100644 --- a/crates/bevy_ecs/src/world/world_cell.rs +++ b/crates/bevy_ecs/src/world/world_cell.rs @@ -157,7 +157,7 @@ impl<'w, T> Deref for WorldBorrowMut<'w, T> { impl<'w, T> DerefMut for WorldBorrowMut<'w, T> { fn deref_mut(&mut self) -> &mut Self::Target { - self.value.deref_mut() + &mut *self.value } }