Added remove_non_send to World (#1716)

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
This commit is contained in:
TheRawMeatball 2021-03-23 00:41:54 +00:00
parent 81b53d15d4
commit 47004dfcb4

View file

@ -520,6 +520,22 @@ impl World {
/// Resources are "unique" data of a given type.
#[inline]
pub fn remove_resource<T: Component>(&mut self) -> Option<T> {
// SAFE: T is Send + Sync
unsafe { self.remove_resource_unchecked() }
}
#[inline]
pub fn remove_non_send<T: 'static>(&mut self) -> Option<T> {
self.validate_non_send_access::<T>();
// 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<T: 'static>(&mut self) -> Option<T> {
let component_id = self.components.get_resource_id(TypeId::of::<T>())?;
let resource_archetype = self.archetypes.resource_mut();
let unique_components = resource_archetype.unique_components_mut();