File tree 4 files changed +13
-35
lines changed
4 files changed +13
-35
lines changed Original file line number Diff line number Diff line change @@ -103,17 +103,15 @@ impl<C: Component + Reflect + FromWorld> FromType<C> for ReflectComponent {
103
103
. entity_mut ( destination_entity)
104
104
. insert ( destination_component) ;
105
105
} ,
106
- reflect_component : |world, entity| unsafe {
106
+ reflect_component : |world, entity| {
107
107
world
108
108
. get_entity ( entity) ?
109
- // SAFE: lifetimes force correct usage of returned data
110
- . get_unchecked :: < C > ( )
109
+ . get :: < C > ( )
111
110
. map ( |c| c as & dyn Reflect )
112
111
} ,
113
112
reflect_component_mut : |world, entity| unsafe {
114
113
world
115
114
. get_entity ( entity) ?
116
- // SAFE: lifetimes force correct usage of returned data
117
115
. get_unchecked_mut :: < C > ( world. last_change_tick ( ) , world. read_change_tick ( ) )
118
116
. map ( |c| ReflectMut {
119
117
value : c. value as & mut dyn Reflect ,
Original file line number Diff line number Diff line change @@ -868,12 +868,9 @@ where
868
868
. archetype_component_access
869
869
. has_read ( archetype_component)
870
870
{
871
- // SAFE: lifetimes enforce correct usage of returned borrow
872
- unsafe {
873
- entity_ref
874
- . get_unchecked :: < T > ( )
875
- . ok_or ( QueryComponentError :: MissingComponent )
876
- }
871
+ entity_ref
872
+ . get :: < T > ( )
873
+ . ok_or ( QueryComponentError :: MissingComponent )
877
874
} else {
878
875
Err ( QueryComponentError :: MissingReadAccess )
879
876
}
Original file line number Diff line number Diff line change @@ -62,26 +62,12 @@ impl<'w> EntityRef<'w> {
62
62
}
63
63
64
64
#[ inline]
65
- pub fn get < T : Component > ( & self ) -> Option < & ' _ T > {
66
- // SAFE: lifetimes enforce correct usage of returned borrow
67
- unsafe { self . get_unchecked :: < T > ( ) }
68
- }
69
-
70
- /// Gets an immutable reference to the component of type `T` associated with
71
- /// this entity without ensuring there are no unique borrows active and without
72
- /// ensuring that the returned reference will stay valid.
73
- ///
74
- /// # Safety
75
- ///
76
- /// - The returned reference must never alias a mutable borrow of this component.
77
- /// - The returned reference must not be used after this component is moved which
78
- /// may happen from **any** `insert_component`, `remove_component` or `despawn`
79
- /// operation on this world (non-exhaustive list).
80
- #[ inline]
81
- pub unsafe fn get_unchecked < T : Component > ( & self ) -> Option < & ' w T > {
65
+ pub fn get < T : Component > ( & self ) -> Option < & ' w T > {
82
66
// SAFE: entity location is valid and returned component is of type T
83
- get_component_with_type ( self . world , TypeId :: of :: < T > ( ) , self . entity , self . location )
84
- . map ( |value| & * value. cast :: < T > ( ) )
67
+ unsafe {
68
+ get_component_with_type ( self . world , TypeId :: of :: < T > ( ) , self . entity , self . location )
69
+ . map ( |value| & * value. cast :: < T > ( ) )
70
+ }
85
71
}
86
72
87
73
/// Gets a mutable reference to the component of type `T` associated with
Original file line number Diff line number Diff line change @@ -197,8 +197,7 @@ impl World {
197
197
/// .insert(Position { x: 0.0, y: 0.0 })
198
198
/// .id();
199
199
///
200
- /// let entity_ref = world.entity(entity);
201
- /// let position = entity_ref.get::<Position>().unwrap();
200
+ /// let position = world.entity(entity).get::<Position>().unwrap();
202
201
/// assert_eq!(position.x, 0.0);
203
202
/// ```
204
203
#[ inline]
@@ -338,8 +337,7 @@ impl World {
338
337
/// .insert_bundle((Num(1), Label("hello"))) // add a bundle of components
339
338
/// .id();
340
339
///
341
- /// let entity_ref = world.entity(entity);
342
- /// let position = entity_ref.get::<Position>().unwrap();
340
+ /// let position = world.entity(entity).get::<Position>().unwrap();
343
341
/// assert_eq!(position.x, 0.0);
344
342
/// ```
345
343
pub fn spawn ( & mut self ) -> EntityMut {
@@ -416,8 +414,7 @@ impl World {
416
414
/// ```
417
415
#[ inline]
418
416
pub fn get < T : Component > ( & self , entity : Entity ) -> Option < & T > {
419
- // SAFE: lifetimes enforce correct usage of returned borrow
420
- unsafe { self . get_entity ( entity) ?. get_unchecked :: < T > ( ) }
417
+ self . get_entity ( entity) ?. get ( )
421
418
}
422
419
423
420
/// Retrieves a mutable reference to the given `entity`'s [Component] of the given type.
You can’t perform that action at this time.
0 commit comments