@@ -80,10 +80,12 @@ unsafe impl Send for UnsafeWorldCell<'_> {}
80
80
unsafe impl Sync for UnsafeWorldCell < ' _ > { }
81
81
82
82
impl < ' w > UnsafeWorldCell < ' w > {
83
+ /// Creates a [`UnsafeWorldCell`] that can be used to access everything immutably
83
84
pub ( crate ) fn new_readonly ( world : & ' w World ) -> Self {
84
85
UnsafeWorldCell ( world as * const World as * mut World , PhantomData )
85
86
}
86
87
88
+ /// Creates [`UnsafeWorldCell`] that can be used to access everything mutably
87
89
pub ( crate ) fn new_mutable ( world : & ' w mut World ) -> Self {
88
90
Self ( world as * mut World , PhantomData )
89
91
}
@@ -818,24 +820,37 @@ unsafe fn get_ticks(
818
820
}
819
821
820
822
#[ inline]
821
- #[ allow( unsafe_op_in_unsafe_fn) ]
823
+ /// # Safety:
824
+ /// - the returned `Column` is only used in ways that the `world` has permission for.
825
+ /// - the returned `Column` is only used in ways that would not conflict with any existing
826
+ /// borrows of world data.
822
827
unsafe fn fetch_table (
823
828
world : UnsafeWorldCell < ' _ > ,
824
829
location : EntityLocation ,
825
830
component_id : ComponentId ,
826
831
) -> Option < ( & Column , TableRow ) > {
827
832
let archetype = & world. archetypes ( ) [ location. archetype_id ] ;
828
- let table = & world. unsafe_world ( ) . storages . tables [ archetype. table_id ( ) ] ;
833
+ // SAFETY: caller ensures returned data is not misused and we have not created any borrows
834
+ // of component/resource data
835
+ let table = & unsafe { world. unsafe_world ( ) } . storages . tables [ archetype. table_id ( ) ] ;
829
836
let components = table. get_column ( component_id) ?;
830
837
let table_row = archetype. entity_table_row ( location. archetype_row ) ;
831
838
Some ( ( components, table_row) )
832
839
}
833
840
834
841
#[ inline]
835
- #[ allow( unsafe_op_in_unsafe_fn) ]
842
+ /// # Safety:
843
+ /// - the returned `ComponentSparseSet` is only used in ways that the `world` has permission for.
844
+ /// - the returned `ComponentSparseSet` is only used in ways that would not conflict with any existing
845
+ /// borrows of world data.
836
846
unsafe fn fetch_sparse_set (
837
847
world : UnsafeWorldCell < ' _ > ,
838
848
component_id : ComponentId ,
839
849
) -> Option < & ComponentSparseSet > {
840
- world. unsafe_world ( ) . storages . sparse_sets . get ( component_id)
850
+ // SAFETY: caller ensures returned data is not misused and we have not created any borrows
851
+ // of component/resource data
852
+ unsafe { world. unsafe_world ( ) }
853
+ . storages
854
+ . sparse_sets
855
+ . get ( component_id)
841
856
}
0 commit comments