@@ -67,21 +67,29 @@ impl<'w> EntityRef<'w> {
67
67
unsafe { self . get_unchecked :: < T > ( ) }
68
68
}
69
69
70
- /// This allows aliased mutability use after free bugs.
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.
71
73
/// # Safety
72
- /// - Must not be a mutable reference to the component.
73
- /// - Must not use the returned reference after the component is removed
74
+ /// - The returned reference must never alias a mutable borrow of this component.
75
+ /// - The returned reference must not be used after this component is moved which
76
+ /// may happen from **any** `insert_component`, `remove_component` or `despawn`
77
+ /// operation on this world (non-exhaustive list).
74
78
#[ inline]
75
79
pub unsafe fn get_unchecked < T : Component > ( & self ) -> Option < & ' w T > {
76
80
// SAFE: entity location is valid and returned component is of type T
77
81
get_component_with_type ( self . world , TypeId :: of :: < T > ( ) , self . entity , self . location )
78
82
. map ( |value| & * value. cast :: < T > ( ) )
79
83
}
80
84
81
- /// This allows aliased mutability and use after free bugs.
85
+ /// Gets a mutable reference to the component of type `T` associated with
86
+ /// this entity without ensuring there are no other borrows active and without
87
+ /// ensuring that the returned reference will stay valid.
82
88
/// # Safety
83
- /// - Must not be any other references to the component.
84
- /// - Must not use the returned reference after the component is removed.
89
+ /// - The returned reference must never alias a mutable borrow of this component.
90
+ /// - The returned reference must not be used after this component is moved which
91
+ /// may happen from **any** `insert_component`, `remove_component` or `despawn`
92
+ /// operation on this world (non-exhaustive list).
85
93
#[ inline]
86
94
pub unsafe fn get_unchecked_mut < T : Component > (
87
95
& self ,
@@ -165,21 +173,29 @@ impl<'w> EntityMut<'w> {
165
173
unsafe { self . get_unchecked_mut :: < T > ( ) }
166
174
}
167
175
168
- /// This allows aliased mutability use after free bugs.
176
+ /// Gets an immutable reference to the component of type `T` associated with
177
+ /// this entity without ensuring there are no unique borrows active and without
178
+ /// ensuring that the returned reference will stay valid.
169
179
/// # Safety
170
- /// - Must not be a mutable reference to the component.
171
- /// - Must not use the returned reference after the component is removed
180
+ /// - The returned reference must never alias a mutable borrow of this component.
181
+ /// - The returned reference must not be used after this component is moved which
182
+ /// may happen from **any** `insert_component`, `remove_component` or `despawn`
183
+ /// operation on this world (non-exhaustive list).
172
184
#[ inline]
173
185
pub unsafe fn get_unchecked < T : Component > ( & self ) -> Option < & ' w T > {
174
186
// SAFE: entity location is valid and returned component is of type T
175
187
get_component_with_type ( self . world , TypeId :: of :: < T > ( ) , self . entity , self . location )
176
188
. map ( |value| & * value. cast :: < T > ( ) )
177
189
}
178
190
179
- /// This allows aliased mutability and use after free bugs.
191
+ /// Gets a mutable reference to the component of type `T` associated with
192
+ /// this entity without ensuring there are no other borrows active and without
193
+ /// ensuring that the returned reference will stay valid.
180
194
/// # Safety
181
- /// - Must not be any other references to the component.
182
- /// - Must not use the returned reference after the component is removed.
195
+ /// - The returned reference must never alias a mutable borrow of this component.
196
+ /// - The returned reference must not be used after this component is moved which
197
+ /// may happen from **any** `insert_component`, `remove_component` or `despawn`
198
+ /// operation on this world (non-exhaustive list).
183
199
#[ inline]
184
200
pub unsafe fn get_unchecked_mut < T : Component > ( & self ) -> Option < Mut < ' w , T > > {
185
201
get_component_and_ticks_with_type ( self . world , TypeId :: of :: < T > ( ) , self . entity , self . location )
0 commit comments