@@ -45,19 +45,19 @@ pub struct ReflectComponent(ReflectComponentFns);
45
45
#[ derive( Clone ) ]
46
46
pub struct ReflectComponentFns {
47
47
/// Function pointer implementing [`ReflectComponent::insert()`].
48
- pub insert : fn ( & mut World , Entity , & dyn Reflect ) ,
48
+ pub insert : fn ( & mut EntityMut , & dyn Reflect ) ,
49
49
/// Function pointer implementing [`ReflectComponent::apply()`].
50
50
pub apply : fn ( & mut EntityMut , & dyn Reflect ) ,
51
51
/// Function pointer implementing [`ReflectComponent::apply_or_insert()`].
52
- pub apply_or_insert : fn ( & mut World , Entity , & dyn Reflect ) ,
52
+ pub apply_or_insert : fn ( & mut EntityMut , & dyn Reflect ) ,
53
53
/// Function pointer implementing [`ReflectComponent::remove()`].
54
54
pub remove : fn ( & mut EntityMut ) ,
55
55
/// Function pointer implementing [`ReflectComponent::contains()`].
56
56
pub contains : fn ( EntityRef ) -> bool ,
57
57
/// Function pointer implementing [`ReflectComponent::reflect()`].
58
58
pub reflect : fn ( EntityRef ) -> Option < & dyn Reflect > ,
59
59
/// Function pointer implementing [`ReflectComponent::reflect_mut()`].
60
- pub reflect_mut : for <' a > fn ( & ' a mut EntityMut ) -> Option < Mut < ' a , dyn Reflect > > ,
60
+ pub reflect_mut : for <' a > fn ( & ' a mut EntityMut < ' _ > ) -> Option < Mut < ' a , dyn Reflect > > ,
61
61
/// Function pointer implementing [`ReflectComponent::reflect_unchecked_mut()`].
62
62
///
63
63
/// # Safety
@@ -81,12 +81,8 @@ impl ReflectComponentFns {
81
81
82
82
impl ReflectComponent {
83
83
/// Insert a reflected [`Component`] into the entity like [`insert()`](crate::world::EntityMut::insert).
84
- ///
85
- /// # Panics
86
- ///
87
- /// Panics if there is no such entity.
88
- pub fn insert ( & self , world : & mut World , entity : Entity , component : & dyn Reflect ) {
89
- ( self . 0 . insert ) ( world, entity, component) ;
84
+ pub fn insert ( & self , entity : & mut EntityMut , component : & dyn Reflect ) {
85
+ ( self . 0 . insert ) ( entity, component) ;
90
86
}
91
87
92
88
/// Uses reflection to set the value of this [`Component`] type in the entity to the given value.
@@ -99,12 +95,8 @@ impl ReflectComponent {
99
95
}
100
96
101
97
/// Uses reflection to set the value of this [`Component`] type in the entity to the given value or insert a new one if it does not exist.
102
- ///
103
- /// # Panics
104
- ///
105
- /// Panics if the `entity` does not exist.
106
- pub fn apply_or_insert ( & self , world : & mut World , entity : Entity , component : & dyn Reflect ) {
107
- ( self . 0 . apply_or_insert ) ( world, entity, component) ;
98
+ pub fn apply_or_insert ( & self , entity : & mut EntityMut , component : & dyn Reflect ) {
99
+ ( self . 0 . apply_or_insert ) ( entity, component) ;
108
100
}
109
101
110
102
/// Removes this [`Component`] type from the entity. Does nothing if it doesn't exist.
@@ -184,22 +176,22 @@ impl ReflectComponent {
184
176
impl < C : Component + Reflect + FromWorld > FromType < C > for ReflectComponent {
185
177
fn from_type ( ) -> Self {
186
178
ReflectComponent ( ReflectComponentFns {
187
- insert : |world , entity, reflected_component| {
188
- let mut component = C :: from_world ( world) ;
179
+ insert : |entity, reflected_component| {
180
+ let mut component = entity . world_scope ( |world| C :: from_world ( world) ) ;
189
181
component. apply ( reflected_component) ;
190
- world . entity_mut ( entity) . insert ( component) ;
182
+ entity. insert ( component) ;
191
183
} ,
192
184
apply : |entity, reflected_component| {
193
185
let mut component = entity. get_mut :: < C > ( ) . unwrap ( ) ;
194
186
component. apply ( reflected_component) ;
195
187
} ,
196
- apply_or_insert : |world , entity, reflected_component| {
197
- if let Some ( mut component) = world . get_mut :: < C > ( entity ) {
188
+ apply_or_insert : |entity, reflected_component| {
189
+ if let Some ( mut component) = entity . get_mut :: < C > ( ) {
198
190
component. apply ( reflected_component) ;
199
191
} else {
200
- let mut component = C :: from_world ( world) ;
192
+ let mut component = entity . world_scope ( |world| C :: from_world ( world) ) ;
201
193
component. apply ( reflected_component) ;
202
- world . entity_mut ( entity) . insert ( component) ;
194
+ entity. insert ( component) ;
203
195
}
204
196
} ,
205
197
remove : |entity| {
0 commit comments