Skip to content

Commit 47004df

Browse files
TheRawMeatballcart
andcommitted
Added remove_non_send to World (#1716)
Co-authored-by: Carter Anderson <[email protected]>
1 parent 81b53d1 commit 47004df

File tree

1 file changed

+16
-0
lines changed
  • crates/bevy_ecs/src/world

1 file changed

+16
-0
lines changed

crates/bevy_ecs/src/world/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,22 @@ impl World {
520520
/// Resources are "unique" data of a given type.
521521
#[inline]
522522
pub fn remove_resource<T: Component>(&mut self) -> Option<T> {
523+
// SAFE: T is Send + Sync
524+
unsafe { self.remove_resource_unchecked() }
525+
}
526+
527+
#[inline]
528+
pub fn remove_non_send<T: 'static>(&mut self) -> Option<T> {
529+
self.validate_non_send_access::<T>();
530+
// SAFE: we are on main thread
531+
unsafe { self.remove_resource_unchecked() }
532+
}
533+
534+
#[inline]
535+
/// # Safety
536+
/// make sure you're on main thread if T isn't Send + Sync
537+
#[allow(unused_unsafe)]
538+
pub unsafe fn remove_resource_unchecked<T: 'static>(&mut self) -> Option<T> {
523539
let component_id = self.components.get_resource_id(TypeId::of::<T>())?;
524540
let resource_archetype = self.archetypes.resource_mut();
525541
let unique_components = resource_archetype.unique_components_mut();

0 commit comments

Comments
 (0)