From 47004dfcb415a049e4c6e68fdf56c26de72f51a1 Mon Sep 17 00:00:00 2001 From: TheRawMeatball Date: Tue, 23 Mar 2021 00:41:54 +0000 Subject: [PATCH] Added remove_non_send to World (#1716) Co-authored-by: Carter Anderson --- crates/bevy_ecs/src/world/mod.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index 0c7111e66d..f17a5522ec 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -520,6 +520,22 @@ impl World { /// Resources are "unique" data of a given type. #[inline] pub fn remove_resource(&mut self) -> Option { + // SAFE: T is Send + Sync + unsafe { self.remove_resource_unchecked() } + } + + #[inline] + pub fn remove_non_send(&mut self) -> Option { + self.validate_non_send_access::(); + // SAFE: we are on main thread + unsafe { self.remove_resource_unchecked() } + } + + #[inline] + /// # Safety + /// make sure you're on main thread if T isn't Send + Sync + #[allow(unused_unsafe)] + pub unsafe fn remove_resource_unchecked(&mut self) -> Option { let component_id = self.components.get_resource_id(TypeId::of::())?; let resource_archetype = self.archetypes.resource_mut(); let unique_components = resource_archetype.unique_components_mut();