@@ -126,39 +126,6 @@ impl<'w> EntityRef<'w> {
126
126
)
127
127
}
128
128
}
129
-
130
- /// Gets a mutable reference to the component of type `T` associated with
131
- /// this entity without ensuring there are no other borrows active and without
132
- /// ensuring that the returned reference will stay valid.
133
- ///
134
- /// # Safety
135
- ///
136
- /// - The returned reference must never alias a mutable borrow of this component.
137
- /// - The returned reference must not be used after this component is moved which
138
- /// may happen from **any** `insert_component`, `remove_component` or `despawn`
139
- /// operation on this world (non-exhaustive list).
140
- #[ inline]
141
- pub unsafe fn get_unchecked_mut < T : Component > (
142
- & self ,
143
- last_change_tick : u32 ,
144
- change_tick : u32 ,
145
- ) -> Option < Mut < ' w , T > > {
146
- // SAFETY:
147
- // - entity location and entity is valid
148
- // - returned component is of type T
149
- // - the storage type provided is correct for T
150
- self . world
151
- . get_component_and_ticks_with_type (
152
- TypeId :: of :: < T > ( ) ,
153
- T :: Storage :: STORAGE_TYPE ,
154
- self . entity ,
155
- self . location ,
156
- )
157
- . map ( |( value, ticks) | Mut {
158
- value : value. assert_unique ( ) . deref_mut :: < T > ( ) ,
159
- ticks : Ticks :: from_tick_cells ( ticks, last_change_tick, change_tick) ,
160
- } )
161
- }
162
129
}
163
130
164
131
impl < ' w > EntityRef < ' w > {
@@ -270,7 +237,23 @@ impl<'w> EntityMut<'w> {
270
237
#[ inline]
271
238
pub fn get_mut < T : Component > ( & mut self ) -> Option < Mut < ' _ , T > > {
272
239
// SAFETY: world access is unique, and lifetimes enforce correct usage of returned borrow
273
- unsafe { self . get_unchecked_mut :: < T > ( ) }
240
+ unsafe {
241
+ self . world
242
+ . get_component_and_ticks_with_type (
243
+ TypeId :: of :: < T > ( ) ,
244
+ T :: Storage :: STORAGE_TYPE ,
245
+ self . entity ,
246
+ self . location ,
247
+ )
248
+ . map ( |( value, cells) | Mut {
249
+ value : value. assert_unique ( ) . deref_mut :: < T > ( ) ,
250
+ ticks : Ticks :: from_tick_cells (
251
+ cells,
252
+ self . world . last_change_tick ,
253
+ self . world . read_change_tick ( ) ,
254
+ ) ,
255
+ } )
256
+ }
274
257
}
275
258
276
259
/// Retrieves the change ticks for the given component. This can be useful for implementing change
@@ -314,39 +297,6 @@ impl<'w> EntityMut<'w> {
314
297
}
315
298
}
316
299
317
- /// Gets a mutable reference to the component of type `T` associated with
318
- /// this entity without ensuring there are no other borrows active and without
319
- /// ensuring that the returned reference will stay valid.
320
- ///
321
- /// # Safety
322
- ///
323
- /// - The returned reference must never alias a mutable borrow of this component.
324
- /// - The returned reference must not be used after this component is moved which
325
- /// may happen from **any** `insert_component`, `remove_component` or `despawn`
326
- /// operation on this world (non-exhaustive list).
327
- #[ inline]
328
- pub unsafe fn get_unchecked_mut < T : Component > ( & self ) -> Option < Mut < ' _ , T > > {
329
- // SAFETY:
330
- // - entity location and entity is valid
331
- // - returned component is of type T
332
- // - the storage type provided is correct for T
333
- self . world
334
- . get_component_and_ticks_with_type (
335
- TypeId :: of :: < T > ( ) ,
336
- T :: Storage :: STORAGE_TYPE ,
337
- self . entity ,
338
- self . location ,
339
- )
340
- . map ( |( value, ticks) | Mut {
341
- value : value. assert_unique ( ) . deref_mut :: < T > ( ) ,
342
- ticks : Ticks :: from_tick_cells (
343
- ticks,
344
- self . world . last_change_tick ( ) ,
345
- self . world . read_change_tick ( ) ,
346
- ) ,
347
- } )
348
- }
349
-
350
300
/// Adds a [`Bundle`] of components to the entity.
351
301
///
352
302
/// This will overwrite any previous value(s) of the same component type.
@@ -694,15 +644,19 @@ impl<'w> EntityMut<'w> {
694
644
}
695
645
}
696
646
697
- fn contains_component_with_type ( world : & World , type_id : TypeId , location : EntityLocation ) -> bool {
647
+ pub ( crate ) fn contains_component_with_type (
648
+ world : & World ,
649
+ type_id : TypeId ,
650
+ location : EntityLocation ,
651
+ ) -> bool {
698
652
if let Some ( component_id) = world. components . get_id ( type_id) {
699
653
contains_component_with_id ( world, component_id, location)
700
654
} else {
701
655
false
702
656
}
703
657
}
704
658
705
- fn contains_component_with_id (
659
+ pub ( crate ) fn contains_component_with_id (
706
660
world : & World ,
707
661
component_id : ComponentId ,
708
662
location : EntityLocation ,
0 commit comments