@@ -96,6 +96,11 @@ impl<'w> InteriorMutableWorld<'w> {
96
96
}
97
97
98
98
/// Gets a reference to the resource of the given type if it exists
99
+ ///
100
+ /// # Safety
101
+ /// All [`InteriorMutableWorld`] methods take `&self` and thus do not check that there is only one unique reference or multiple shared ones.
102
+ /// It is the callers responsibility to make sure that there will never be a mutable reference to a value that has other references pointing to it,
103
+ /// and that no arbitrary safe code can access a `&World` while some value is mutably borrowed.
99
104
#[ inline]
100
105
pub unsafe fn get_resource < R : Resource > ( & self ) -> Option < & ' w R > {
101
106
self . 0 . get_resource :: < R > ( )
@@ -107,12 +112,22 @@ impl<'w> InteriorMutableWorld<'w> {
107
112
///
108
113
/// **You should prefer to use the typed API [`InteriorMutableWorld::get_resource`] where possible and only
109
114
/// use this in cases where the actual types are not known at compile time.**
115
+ ///
116
+ /// # Safety
117
+ /// All [`InteriorMutableWorld`] methods take `&self` and thus do not check that there is only one unique reference or multiple shared ones.
118
+ /// It is the callers responsibility to make sure that there will never be a mutable reference to a value that has other references pointing to it,
119
+ /// and that no arbitrary safe code can access a `&World` while some value is mutably borrowed.
110
120
#[ inline]
111
121
pub unsafe fn get_resource_by_id ( & self , component_id : ComponentId ) -> Option < Ptr < ' w > > {
112
122
self . 0 . get_resource_by_id ( component_id)
113
123
}
114
124
115
125
/// Gets a mutable reference to the resource of the given type if it exists
126
+ ///
127
+ /// # Safety
128
+ /// All [`InteriorMutableWorld`] methods take `&self` and thus do not check that there is only one unique reference or multiple shared ones.
129
+ /// It is the callers responsibility to make sure that there will never be a mutable reference to a value that has other references pointing to it,
130
+ /// and that no arbitrary safe code can access a `&World` while some value is mutably borrowed.
116
131
#[ inline]
117
132
pub unsafe fn get_resource_mut < R : Resource > ( & self ) -> Option < Mut < ' w , R > > {
118
133
let component_id = self . 0 . components . get_resource_id ( TypeId :: of :: < R > ( ) ) ?;
@@ -125,6 +140,11 @@ impl<'w> InteriorMutableWorld<'w> {
125
140
///
126
141
/// **You should prefer to use the typed API [`InteriorMutableWorld::get_resource_mut`] where possible and only
127
142
/// use this in cases where the actual types are not known at compile time.**
143
+ ///
144
+ /// # Safety
145
+ /// All [`InteriorMutableWorld`] methods take `&self` and thus do not check that there is only one unique reference or multiple shared ones.
146
+ /// It is the callers responsibility to make sure that there will never be a mutable reference to a value that has other references pointing to it,
147
+ /// and that no arbitrary safe code can access a `&World` while some value is mutably borrowed.
128
148
#[ inline]
129
149
pub unsafe fn get_resource_mut_by_id (
130
150
& self ,
@@ -156,6 +176,11 @@ impl<'w> InteriorMutableWorld<'w> {
156
176
157
177
/// Gets a reference to the non-send resource of the given type, if it exists.
158
178
/// Otherwise returns [None]
179
+ ///
180
+ /// # Safety
181
+ /// All [`InteriorMutableWorld`] methods take `&self` and thus do not check that there is only one unique reference or multiple shared ones.
182
+ /// It is the callers responsibility to make sure that there will never be a mutable reference to a value that has other references pointing to it,
183
+ /// and that no arbitrary safe code can access a `&World` while some value is mutably borrowed.
159
184
#[ inline]
160
185
pub unsafe fn get_non_send_resource < R : ' static > ( & self ) -> Option < & R > {
161
186
self . 0 . get_non_send_resource :: < R > ( )
@@ -175,6 +200,10 @@ impl<'w> InteriorMutableWorld<'w> {
175
200
/// - `component_id` must be assigned to a component of type `R`
176
201
/// - Caller must ensure this doesn't violate Rust mutability rules for the given resource.
177
202
/// - resource is either Send+Sync or the main thread is validated
203
+ ///
204
+ /// All [`InteriorMutableWorld`] methods take `&self` and thus do not check that there is only one unique reference or multiple shared ones.
205
+ /// It is the callers responsibility to make sure that there will never be a mutable reference to a value that has other references pointing to it,
206
+ /// and that no arbitrary safe code can access a `&World` while some value is mutably borrowed.
178
207
#[ inline]
179
208
pub ( crate ) unsafe fn get_resource_mut_with_id < R > (
180
209
& self ,
@@ -196,6 +225,10 @@ impl<'w> InteriorMutableWorld<'w> {
196
225
/// # Safety
197
226
/// - `component_id` must be assigned to a component of type `R`.
198
227
/// - Caller must ensure this doesn't violate Rust mutability rules for the given resource.
228
+ ///
229
+ /// All [`InteriorMutableWorld`] methods take `&self` and thus do not check that there is only one unique reference or multiple shared ones.
230
+ /// It is the callers responsibility to make sure that there will never be a mutable reference to a value that has other references pointing to it,
231
+ /// and that no arbitrary safe code can access a `&World` while some value is mutably borrowed.
199
232
#[ inline]
200
233
pub ( crate ) unsafe fn get_non_send_mut_with_id < R : ' static > (
201
234
& self ,
@@ -252,6 +285,10 @@ impl<'w> InteriorMutableEntityRef<'w> {
252
285
entity_ref:: contains_component_with_type ( self . world . 0 , type_id, self . location )
253
286
}
254
287
288
+ /// # Safety
289
+ /// All [`InteriorMutableEntityRef`] methods take `&self` and thus do not check that there is only one unique reference or multiple shared ones.
290
+ /// It is the callers responsibility to make sure that there will never be a mutable reference to a value that has other references pointing to it,
291
+ /// and that no arbitrary safe code can access a `&World` while some value is mutably borrowed.
255
292
#[ inline]
256
293
pub unsafe fn get < T : Component > ( & self ) -> Option < & ' w T > {
257
294
// SAFETY:
@@ -276,6 +313,11 @@ impl<'w> InteriorMutableEntityRef<'w> {
276
313
277
314
/// Retrieves the change ticks for the given component. This can be useful for implementing change
278
315
/// detection in custom runtimes.
316
+ ///
317
+ /// # Safety
318
+ /// All [`InteriorMutableEntityRef`] methods take `&self` and thus do not check that there is only one unique reference or multiple shared ones.
319
+ /// It is the callers responsibility to make sure that there will never be a mutable reference to a value that has other references pointing to it,
320
+ /// and that no arbitrary safe code can access a `&World` while some value is mutably borrowed.
279
321
#[ inline]
280
322
pub unsafe fn get_change_ticks < T : Component > ( & self ) -> Option < & ' w ComponentTicks > {
281
323
// SAFETY:
@@ -298,6 +340,10 @@ impl<'w> InteriorMutableEntityRef<'w> {
298
340
}
299
341
}
300
342
343
+ /// # Safety
344
+ /// All [`InteriorMutableEntityRef`] methods take `&self` and thus do not check that there is only one unique reference or multiple shared ones.
345
+ /// It is the callers responsibility to make sure that there will never be a mutable reference to a value that has other references pointing to it,
346
+ /// and that no arbitrary safe code can access a `&World` while some value is mutably borrowed.
301
347
#[ inline]
302
348
pub unsafe fn get_mut < T : Component > ( & self ) -> Option < Mut < ' w , T > > {
303
349
// SAFETY: same safety requirements
@@ -309,6 +355,10 @@ impl<'w> InteriorMutableEntityRef<'w> {
309
355
}
310
356
}
311
357
358
+ /// # Safety
359
+ /// All [`InteriorMutableEntityRef`] methods take `&self` and thus do not check that there is only one unique reference or multiple shared ones.
360
+ /// It is the callers responsibility to make sure that there will never be a mutable reference to a value that has other references pointing to it,
361
+ /// and that no arbitrary safe code can access a `&World` while some value is mutably borrowed.
312
362
#[ inline]
313
363
pub unsafe fn get_mut_using_ticks < T : Component > (
314
364
& self ,
@@ -347,6 +397,11 @@ impl<'w> InteriorMutableEntityRef<'w> {
347
397
///
348
398
/// Unlike [`InteriorMutableEntityRef::get`], this returns a raw pointer to the component,
349
399
/// which is only valid while the `'w` borrow of the lifetime is active.
400
+ ///
401
+ /// # Safety
402
+ /// All [`InteriorMutableEntityRef`] methods take `&self` and thus do not check that there is only one unique reference or multiple shared ones.
403
+ /// It is the callers responsibility to make sure that there will never be a mutable reference to a value that has other references pointing to it,
404
+ /// and that no arbitrary safe code can access a `&World` while some value is mutably borrowed.
350
405
#[ inline]
351
406
pub unsafe fn get_by_id ( & self , component_id : ComponentId ) -> Option < Ptr < ' w > > {
352
407
self . world . 0 . components . get_info ( component_id) ?;
@@ -367,6 +422,11 @@ impl<'w> InteriorMutableEntityRef<'w> {
367
422
///
368
423
/// **You should prefer to use the typed API [`InteriorMutableEntityRef::get_mut`] where possible and only
369
424
/// use this in cases where the actual types are not known at compile time.**
425
+ ///
426
+ /// # Safety
427
+ /// All [`InteriorMutableEntityRef`] methods take `&self` and thus do not check that there is only one unique reference or multiple shared ones.
428
+ /// It is the callers responsibility to make sure that there will never be a mutable reference to a value that has other references pointing to it,
429
+ /// and that no arbitrary safe code can access a `&World` while some value is mutably borrowed.
370
430
#[ inline]
371
431
pub unsafe fn get_mut_by_id ( & self , component_id : ComponentId ) -> Option < MutUntyped < ' w > > {
372
432
self . world . 0 . components . get_info ( component_id) ?;
0 commit comments