@@ -44,17 +44,17 @@ pub struct ReflectComponentFns {
44
44
/// Function pointer implementing [`ReflectComponent::insert()`].
45
45
pub insert : fn ( & mut World , Entity , & dyn Reflect ) ,
46
46
/// Function pointer implementing [`ReflectComponent::apply()`].
47
- pub apply : fn ( EntityMut , & dyn Reflect ) ,
47
+ pub apply : fn ( & mut EntityMut , & dyn Reflect ) ,
48
48
/// Function pointer implementing [`ReflectComponent::apply_or_insert()`].
49
49
pub apply_or_insert : fn ( & mut World , Entity , & dyn Reflect ) ,
50
50
/// Function pointer implementing [`ReflectComponent::remove()`].
51
- pub remove : fn ( EntityMut ) ,
51
+ pub remove : fn ( & mut EntityMut ) ,
52
52
/// Function pointer implementing [`ReflectComponent::contains()`].
53
- pub contains : fn ( EntityRef ) -> bool ,
53
+ pub contains : fn ( & EntityRef ) -> bool ,
54
54
/// Function pointer implementing [`ReflectComponent::reflect()`].
55
- pub reflect : fn ( EntityRef ) -> Option < & dyn Reflect > ,
55
+ pub reflect : for < ' a > fn ( & ' a EntityRef ) -> Option < & ' a dyn Reflect > ,
56
56
/// Function pointer implementing [`ReflectComponent::reflect_mut()`].
57
- pub reflect_mut : unsafe fn ( & World , Entity ) -> Option < Mut < dyn Reflect > > ,
57
+ pub reflect_mut : for < ' a > fn ( & ' a mut EntityMut ) -> Option < Mut < ' a , dyn Reflect > > ,
58
58
/// Function pointer implementing [`ReflectComponent::copy()`].
59
59
pub copy : fn ( & World , & mut World , Entity , Entity ) ,
60
60
}
@@ -85,7 +85,7 @@ impl ReflectComponent {
85
85
/// # Panics
86
86
///
87
87
/// Panics if there is no [`Component`] of the given type.
88
- pub fn apply ( & self , entity : EntityMut , component : & dyn Reflect ) {
88
+ pub fn apply ( & self , entity : & mut EntityMut , component : & dyn Reflect ) {
89
89
( self . 0 . apply ) ( entity, component) ;
90
90
}
91
91
@@ -103,42 +103,23 @@ impl ReflectComponent {
103
103
/// # Panics
104
104
///
105
105
/// Panics if there is no [`Component`] of the given type.
106
- pub fn remove ( & self , entity : EntityMut ) {
106
+ pub fn remove ( & self , entity : & mut EntityMut ) {
107
107
( self . 0 . remove ) ( entity) ;
108
108
}
109
109
110
110
/// Returns whether entity contains this [`Component`]
111
- pub fn contains ( & self , entity : EntityRef ) -> bool {
111
+ pub fn contains ( & self , entity : & EntityRef ) -> bool {
112
112
( self . 0 . contains ) ( entity)
113
113
}
114
114
115
115
/// Gets the value of this [`Component`] type from the entity as a reflected reference.
116
- pub fn reflect < ' a > ( & self , entity : EntityRef < ' a > ) -> Option < & ' a dyn Reflect > {
116
+ pub fn reflect < ' a > ( & self , entity : & ' a EntityRef < ' a > ) -> Option < & ' a dyn Reflect > {
117
117
( self . 0 . reflect ) ( entity)
118
118
}
119
119
120
120
/// Gets the value of this [`Component`] type from the entity as a mutable reflected reference.
121
- pub fn reflect_mut < ' a > (
122
- & self ,
123
- world : & ' a mut World ,
124
- entity : Entity ,
125
- ) -> Option < Mut < ' a , dyn Reflect > > {
126
- // SAFETY: unique world access
127
- unsafe { ( self . 0 . reflect_mut ) ( world, entity) }
128
- }
129
-
130
- /// # Safety
131
- /// This method does not prevent you from having two mutable pointers to the same data,
132
- /// violating Rust's aliasing rules. To avoid this:
133
- /// * Only call this method in an exclusive system to avoid sharing across threads (or use a
134
- /// scheduler that enforces safe memory access).
135
- /// * Don't call this method more than once in the same scope for a given [`Component`].
136
- pub unsafe fn reflect_unchecked_mut < ' a > (
137
- & self ,
138
- world : & ' a World ,
139
- entity : Entity ,
140
- ) -> Option < Mut < ' a , dyn Reflect > > {
141
- ( self . 0 . reflect_mut ) ( world, entity)
121
+ pub fn reflect_mut < ' a > ( & self , entity : & ' a mut EntityMut < ' a > ) -> Option < Mut < ' a , dyn Reflect > > {
122
+ ( self . 0 . reflect_mut ) ( entity)
142
123
}
143
124
144
125
/// Gets the value of this [`Component`] type from entity from `source_world` and [applies](Self::apply()) it to the value of this [`Component`] type in entity in `destination_world`.
@@ -185,7 +166,7 @@ impl<C: Component + Reflect + FromWorld> FromType<C> for ReflectComponent {
185
166
component. apply ( reflected_component) ;
186
167
world. entity_mut ( entity) . insert ( component) ;
187
168
} ,
188
- apply : |mut entity, reflected_component| {
169
+ apply : |entity, reflected_component| {
189
170
let mut component = entity. get_mut :: < C > ( ) . unwrap ( ) ;
190
171
component. apply ( reflected_component) ;
191
172
} ,
@@ -198,7 +179,7 @@ impl<C: Component + Reflect + FromWorld> FromType<C> for ReflectComponent {
198
179
world. entity_mut ( entity) . insert ( component) ;
199
180
}
200
181
} ,
201
- remove : |mut entity| {
182
+ remove : |entity| {
202
183
entity. remove :: < C > ( ) ;
203
184
} ,
204
185
contains : |entity| entity. contains :: < C > ( ) ,
@@ -211,18 +192,11 @@ impl<C: Component + Reflect + FromWorld> FromType<C> for ReflectComponent {
211
192
. insert ( destination_component) ;
212
193
} ,
213
194
reflect : |entity| entity. get :: < C > ( ) . map ( |c| c as & dyn Reflect ) ,
214
- reflect_mut : |world, entity| {
215
- // SAFETY: reflect_mut is an unsafe function pointer used by `reflect_unchecked_mut` which promises to never
216
- // produce aliasing mutable references, and reflect_mut, which has mutable world access
217
- unsafe {
218
- world
219
- . get_entity ( entity) ?
220
- . get_unchecked_mut :: < C > ( world. last_change_tick ( ) , world. read_change_tick ( ) )
221
- . map ( |c| Mut {
222
- value : c. value as & mut dyn Reflect ,
223
- ticks : c. ticks ,
224
- } )
225
- }
195
+ reflect_mut : |entity| {
196
+ entity. get_mut :: < C > ( ) . map ( |c| Mut {
197
+ value : c. value as & mut dyn Reflect ,
198
+ ticks : c. ticks ,
199
+ } )
226
200
} ,
227
201
} )
228
202
}
0 commit comments