@@ -143,6 +143,17 @@ impl<'w> InteriorMutableWorld<'w> {
143
143
self . 0 . get_resource_by_id ( component_id)
144
144
}
145
145
146
+ /// Gets a reference to the non-send resource of the given type if it exists
147
+ ///
148
+ /// # Safety
149
+ /// All [`InteriorMutableWorld`] methods take `&self` and thus do not check that there is only one unique reference or multiple shared ones.
150
+ /// 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,
151
+ /// and that no arbitrary safe code can access a `&World` while some value is mutably borrowed.
152
+ #[ inline]
153
+ pub unsafe fn get_non_send_resource < R : ' static > ( & self ) -> Option < & ' w R > {
154
+ self . 0 . get_non_send_resource ( )
155
+ }
156
+
146
157
/// Gets a mutable reference to the resource of the given type if it exists
147
158
///
148
159
/// # Safety
@@ -195,6 +206,23 @@ impl<'w> InteriorMutableWorld<'w> {
195
206
ticks,
196
207
} )
197
208
}
209
+
210
+ /// Gets a mutable reference to the non-send resource of the given type if it exists
211
+ ///
212
+ /// # Safety
213
+ /// All [`InteriorMutableWorld`] methods take `&self` and thus do not check that there is only one unique reference or multiple shared ones.
214
+ /// 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,
215
+ /// and that no arbitrary safe code can access a `&World` while some value is mutably borrowed.
216
+ #[ inline]
217
+ pub unsafe fn get_non_send_resource_mut < R : ' static > ( & self ) -> Option < Mut < ' w , R > > {
218
+ self . 0 . validate_non_send_access :: < R > ( ) ;
219
+ let component_id = self . components ( ) . get_resource_id ( TypeId :: of :: < R > ( ) ) ?;
220
+ // SAFETY:
221
+ // - `component_id` is type `R`
222
+ // - we have unique access
223
+ // - main thread is validated
224
+ unsafe { self . get_resource_mut_with_id ( component_id) }
225
+ }
198
226
}
199
227
200
228
impl < ' w > InteriorMutableWorld < ' w > {
@@ -226,21 +254,4 @@ impl<'w> InteriorMutableWorld<'w> {
226
254
ticks,
227
255
} )
228
256
}
229
-
230
- /// # Safety
231
- /// - `component_id` must be assigned to a component of type `R`.
232
- /// - Caller must ensure this doesn't violate Rust mutability rules for the given resource.
233
- ///
234
- /// All [`InteriorMutableWorld`] methods take `&self` and thus do not check that there is only one unique reference or multiple shared ones.
235
- /// 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,
236
- /// and that no arbitrary safe code can access a `&World` while some value is mutably borrowed.
237
- #[ inline]
238
- pub ( crate ) unsafe fn get_non_send_mut_with_id < R : ' static > (
239
- & self ,
240
- component_id : ComponentId ,
241
- ) -> Option < Mut < ' w , R > > {
242
- self . 0 . validate_non_send_access :: < R > ( ) ;
243
- // SAFETY: we validated nonsend access, the rest of the requirements are deferred to caller
244
- unsafe { self . get_resource_mut_with_id ( component_id) }
245
- }
246
257
}
0 commit comments