@@ -80,10 +80,12 @@ unsafe impl Send for UnsafeWorldCell<'_> {}
8080unsafe impl Sync for UnsafeWorldCell < ' _ > { }
8181
8282impl < ' w > UnsafeWorldCell < ' w > {
83+ /// Creates a [`UnsafeWorldCell`] that can be used to access everything immutably
8384 pub ( crate ) fn new_readonly ( world : & ' w World ) -> Self {
8485 UnsafeWorldCell ( world as * const World as * mut World , PhantomData )
8586 }
8687
88+ /// Creates [`UnsafeWorldCell`] that can be used to access everything mutably
8789 pub ( crate ) fn new_mutable ( world : & ' w mut World ) -> Self {
8890 Self ( world as * mut World , PhantomData )
8991 }
@@ -818,24 +820,37 @@ unsafe fn get_ticks(
818820}
819821
820822#[ 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.
822827unsafe fn fetch_table (
823828 world : UnsafeWorldCell < ' _ > ,
824829 location : EntityLocation ,
825830 component_id : ComponentId ,
826831) -> Option < ( & Column , TableRow ) > {
827832 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 ( ) ] ;
829836 let components = table. get_column ( component_id) ?;
830837 let table_row = archetype. entity_table_row ( location. archetype_row ) ;
831838 Some ( ( components, table_row) )
832839}
833840
834841#[ 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.
836846unsafe fn fetch_sparse_set (
837847 world : UnsafeWorldCell < ' _ > ,
838848 component_id : ComponentId ,
839849) -> 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)
841856}
0 commit comments