Skip to content

Commit 9d4cc02

Browse files
add as_interior_mutable(&mut self), as_interior_mutable_readonly(&self) and temporary migration method
1 parent 3bb5752 commit 9d4cc02

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

crates/bevy_ecs/src/system/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> Query<'w, 's, Q, F> {
11821182
}
11831183
let world = self.world;
11841184
let entity_ref = world
1185-
.as_interior_mutable()
1185+
.as_interior_mutable_migration_internal()
11861186
.get_entity(entity)
11871187
.ok_or(QueryComponentError::NoSuchEntity)?;
11881188
let component_id = world

crates/bevy_ecs/src/system/system_param.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ unsafe impl<'a, T: Resource> SystemParam for ResMut<'a, T> {
536536
change_tick: u32,
537537
) -> Self::Item<'w, 's> {
538538
let value = world
539-
.as_interior_mutable()
539+
.as_interior_mutable_migration_internal()
540540
.get_resource_mut_with_id(component_id)
541541
.unwrap_or_else(|| {
542542
panic!(
@@ -574,7 +574,7 @@ unsafe impl<'a, T: Resource> SystemParam for Option<ResMut<'a, T>> {
574574
change_tick: u32,
575575
) -> Self::Item<'w, 's> {
576576
world
577-
.as_interior_mutable()
577+
.as_interior_mutable_migration_internal()
578578
.get_resource_mut_with_id(component_id)
579579
.map(|value| ResMut {
580580
value: value.value,

crates/bevy_ecs/src/world/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,19 @@ impl World {
105105
self.id
106106
}
107107

108-
pub fn as_interior_mutable(&self) -> InteriorMutableWorld<'_> {
108+
/// Creates a new [`InteriorMutableWorld`] view with complete read+write access
109+
pub fn as_interior_mutable(&mut self) -> InteriorMutableWorld<'_> {
110+
InteriorMutableWorld::new(self)
111+
}
112+
/// Creates a new [`InteriorMutableWorld`] view only read access to everything
113+
pub fn as_interior_mutable_readonly(&self) -> InteriorMutableWorld<'_> {
114+
InteriorMutableWorld::new(self)
115+
}
116+
117+
/// Creates a new [`InteriorMutableWorld`] with read+write access from a [&World](World).
118+
/// This is only a temporary measure until every `&World` that is semantically a [InteriorMutableWorld]
119+
/// has been replaced.
120+
pub(crate) fn as_interior_mutable_migration_internal(&self) -> InteriorMutableWorld<'_> {
109121
InteriorMutableWorld::new(self)
110122
}
111123

crates/bevy_ecs/src/world/world_cell.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl<'w> WorldCell<'w> {
228228
// SAFETY: ComponentId matches TypeId and access is checked by WorldBorrowMut
229229
|| unsafe {
230230
self.world
231-
.as_interior_mutable()
231+
.as_interior_mutable_migration_internal()
232232
.get_resource_mut_with_id(component_id)
233233
},
234234
archetype_component_id,
@@ -298,7 +298,7 @@ impl<'w> WorldCell<'w> {
298298
// SAFETY: access is checked by WorldBorrowMut
299299
|| unsafe {
300300
self.world
301-
.as_interior_mutable()
301+
.as_interior_mutable_migration_internal()
302302
.get_non_send_resource_mut::<T>()
303303
},
304304
archetype_component_id,

0 commit comments

Comments
 (0)