Skip to content

Commit 913a272

Browse files
add as_interior_mutable(&mut self), as_interior_mutable_readonly(&self) and temporary migration method
1 parent cf91880 commit 913a272

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
@@ -1173,7 +1173,7 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> Query<'w, 's, Q, F> {
11731173
}
11741174
let world = self.world;
11751175
let entity_ref = world
1176-
.as_interior_mutable()
1176+
.as_interior_mutable_migration_internal()
11771177
.get_entity(entity)
11781178
.ok_or(QueryComponentError::NoSuchEntity)?;
11791179
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
@@ -521,7 +521,7 @@ impl<'w, 's, T: Resource> SystemParamFetch<'w, 's> for ResMutState<T> {
521521
change_tick: u32,
522522
) -> Self::Item {
523523
let value = world
524-
.as_interior_mutable()
524+
.as_interior_mutable_migration_internal()
525525
.get_resource_mut_with_id(state.component_id)
526526
.unwrap_or_else(|| {
527527
panic!(
@@ -570,7 +570,7 @@ impl<'w, 's, T: Resource> SystemParamFetch<'w, 's> for OptionResMutState<T> {
570570
change_tick: u32,
571571
) -> Self::Item {
572572
world
573-
.as_interior_mutable()
573+
.as_interior_mutable_migration_internal()
574574
.get_resource_mut_with_id(state.0.component_id)
575575
.map(|value| ResMut {
576576
value: value.value,

crates/bevy_ecs/src/world/mod.rs

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

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

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)