@@ -808,15 +808,18 @@ fn sorted_remove<T: Eq + Ord + Copy>(source: &mut Vec<T>, remove: &[T]) {
808
808
809
809
// SAFETY: EntityLocation must be valid
810
810
#[ inline]
811
- pub ( crate ) unsafe fn get_mut < T : Component > (
812
- world : & mut World ,
811
+ pub ( crate ) unsafe fn get_mut < ' w , T : Component > (
812
+ world : & ' w mut World ,
813
813
entity : Entity ,
814
814
location : EntityLocation ,
815
- ) -> Option < Mut < ' _ , T > > {
816
- // SAFETY: world access is unique, entity location is valid, and returned component is of type
817
- // T
815
+ ) -> Option < Mut < ' w , T > > {
818
816
let change_tick = world. change_tick ( ) ;
819
817
let last_change_tick = world. last_change_tick ( ) ;
818
+ // SAFETY:
819
+ // - world access is unique
820
+ // - entity location is valid
821
+ // - and returned component is of type T
822
+ // - archetypes and components comes from the same world
820
823
world
821
824
. storages
822
825
. get_component_and_ticks_with_type (
@@ -827,8 +830,12 @@ pub(crate) unsafe fn get_mut<T: Component>(
827
830
location,
828
831
)
829
832
. map ( |( value, ticks) | Mut {
833
+ // SAFETY:
834
+ // - world access is unique and ties world lifetime to `Mut` lifetime
835
+ // - `value` is of type `T`
830
836
value : value. assert_unique ( ) . deref_mut :: < T > ( ) ,
831
837
ticks : Ticks {
838
+ // SAFETY: world access is unique and ties world lifetime to `Mut` lifetime
832
839
component_ticks : ticks. deref_mut ( ) ,
833
840
last_change_tick,
834
841
change_tick,
@@ -844,7 +851,11 @@ pub(crate) unsafe fn get_mut_by_id(
844
851
location : EntityLocation ,
845
852
component_id : ComponentId ,
846
853
) -> Option < MutUntyped > {
847
- // SAFETY: world access is unique, entity location and component_id required to be valid
854
+ // SAFETY:
855
+ // - world access is unique
856
+ // - entity location is valid
857
+ // - and returned component is of type T
858
+ // - archetypes and components comes from the same world
848
859
world
849
860
. storages
850
861
. get_component_and_ticks (
@@ -855,8 +866,10 @@ pub(crate) unsafe fn get_mut_by_id(
855
866
location,
856
867
)
857
868
. map ( |( value, ticks) | MutUntyped {
869
+ // SAFETY: world access is unique and ties world lifetime to `MutUntyped` lifetime
858
870
value : value. assert_unique ( ) ,
859
871
ticks : Ticks {
872
+ // SAFETY: world access is unique and ties world lifetime to `Mut` lifetime
860
873
component_ticks : ticks. deref_mut ( ) ,
861
874
last_change_tick : world. last_change_tick ( ) ,
862
875
change_tick : world. read_change_tick ( ) ,
0 commit comments