@@ -913,7 +913,7 @@ impl World {
913
913
#[ inline]
914
914
pub fn get_resource_mut < R : Resource > ( & mut self ) -> Option < Mut < ' _ , R > > {
915
915
// SAFETY: unique world access
916
- unsafe { self . get_resource_unchecked_mut ( ) }
916
+ unsafe { self . as_interior_mutable ( ) . get_resource_mut ( ) }
917
917
}
918
918
919
919
// PERF: optimize this to avoid redundant lookups
@@ -930,18 +930,6 @@ impl World {
930
930
self . resource_mut ( )
931
931
}
932
932
933
- /// Gets a mutable reference to the resource of the given type, if it exists
934
- /// Otherwise returns [None]
935
- ///
936
- /// # Safety
937
- /// This will allow aliased mutable access to the given resource type. The caller must ensure
938
- /// that there is either only one mutable access or multiple immutable accesses at a time.
939
- #[ inline]
940
- pub unsafe fn get_resource_unchecked_mut < R : Resource > ( & self ) -> Option < Mut < ' _ , R > > {
941
- let component_id = self . components . get_resource_id ( TypeId :: of :: < R > ( ) ) ?;
942
- self . get_resource_unchecked_mut_with_id ( component_id)
943
- }
944
-
945
933
/// Gets an immutable reference to the non-send resource of the given type, if it exists.
946
934
///
947
935
/// # Panics
@@ -995,20 +983,16 @@ impl World {
995
983
/// Otherwise returns [None]
996
984
#[ inline]
997
985
pub fn get_non_send_resource_mut < R : ' static > ( & mut self ) -> Option < Mut < ' _ , R > > {
998
- // SAFETY: unique world access
999
- unsafe { self . get_non_send_resource_unchecked_mut ( ) }
1000
- }
1001
-
1002
- /// Gets a mutable reference to the non-send resource of the given type, if it exists.
1003
- /// Otherwise returns [None]
1004
- ///
1005
- /// # Safety
1006
- /// This will allow aliased mutable access to the given non-send resource type. The caller must
1007
- /// ensure that there is either only one mutable access or multiple immutable accesses at a time.
1008
- #[ inline]
1009
- pub unsafe fn get_non_send_resource_unchecked_mut < R : ' static > ( & self ) -> Option < Mut < ' _ , R > > {
986
+ self . validate_non_send_access :: < R > ( ) ;
1010
987
let component_id = self . components . get_resource_id ( TypeId :: of :: < R > ( ) ) ?;
1011
- self . get_non_send_unchecked_mut_with_id ( component_id)
988
+ // SAFETY:
989
+ // - `component_id` is type `R`
990
+ // - we have unique access
991
+ // - main thread is validated
992
+ unsafe {
993
+ self . as_interior_mutable ( )
994
+ . get_resource_mut_with_id ( component_id)
995
+ }
1012
996
}
1013
997
1014
998
// Shorthand helper function for getting the data and change ticks for a resource.
@@ -1278,21 +1262,6 @@ impl World {
1278
1262
. map ( |ptr| ptr. deref ( ) )
1279
1263
}
1280
1264
1281
- /// # Safety
1282
- /// `component_id` must be assigned to a component of type `R`
1283
- /// Caller must ensure this doesn't violate Rust mutability rules for the given resource.
1284
- #[ inline]
1285
- pub ( crate ) unsafe fn get_resource_unchecked_mut_with_id < R > (
1286
- & self ,
1287
- component_id : ComponentId ,
1288
- ) -> Option < Mut < ' _ , R > > {
1289
- let ( ptr, ticks) = self . get_resource_with_ticks ( component_id) ?;
1290
- Some ( Mut {
1291
- value : ptr. assert_unique ( ) . deref_mut ( ) ,
1292
- ticks : Ticks :: from_tick_cells ( ticks, self . last_change_tick ( ) , self . read_change_tick ( ) ) ,
1293
- } )
1294
- }
1295
-
1296
1265
/// # Safety
1297
1266
/// `component_id` must be assigned to a component of type `R`
1298
1267
#[ inline]
@@ -1304,18 +1273,6 @@ impl World {
1304
1273
self . get_resource_with_id ( component_id)
1305
1274
}
1306
1275
1307
- /// # Safety
1308
- /// `component_id` must be assigned to a component of type `R`.
1309
- /// Caller must ensure this doesn't violate Rust mutability rules for the given resource.
1310
- #[ inline]
1311
- pub ( crate ) unsafe fn get_non_send_unchecked_mut_with_id < R : ' static > (
1312
- & self ,
1313
- component_id : ComponentId ,
1314
- ) -> Option < Mut < ' _ , R > > {
1315
- self . validate_non_send_access :: < R > ( ) ;
1316
- self . get_resource_unchecked_mut_with_id ( component_id)
1317
- }
1318
-
1319
1276
/// Inserts a new resource with the given `value`. Will replace the value if it already existed.
1320
1277
///
1321
1278
/// **You should prefer to use the typed API [`World::insert_resource`] where possible and only
@@ -1470,25 +1427,11 @@ impl World {
1470
1427
/// use this in cases where the actual types are not known at compile time.**
1471
1428
#[ inline]
1472
1429
pub fn get_resource_mut_by_id ( & mut self , component_id : ComponentId ) -> Option < MutUntyped < ' _ > > {
1473
- let info = self . components . get_info ( component_id) ?;
1474
- if !info. is_send_and_sync ( ) {
1475
- self . validate_non_send_access_untyped ( info. name ( ) ) ;
1430
+ // SAFETY: unique world access
1431
+ unsafe {
1432
+ self . as_interior_mutable ( )
1433
+ . get_resource_mut_by_id ( component_id)
1476
1434
}
1477
-
1478
- let change_tick = self . change_tick ( ) ;
1479
-
1480
- let ( ptr, ticks) = self . get_resource_with_ticks ( component_id) ?;
1481
-
1482
- // SAFETY: This function has exclusive access to the world so nothing aliases `ticks`.
1483
- // - index is in-bounds because the column is initialized and non-empty
1484
- // - no other reference to the ticks of the same row can exist at the same time
1485
- let ticks = unsafe { Ticks :: from_tick_cells ( ticks, self . last_change_tick ( ) , change_tick) } ;
1486
-
1487
- Some ( MutUntyped {
1488
- // SAFETY: This function has exclusive access to the world so nothing aliases `ptr`.
1489
- value : unsafe { ptr. assert_unique ( ) } ,
1490
- ticks,
1491
- } )
1492
1435
}
1493
1436
1494
1437
/// Removes the resource of a given type, if it exists. Otherwise returns [None].
0 commit comments