Skip to content

Commit

Permalink
Added remove_non_send to World (#1716)
Browse files Browse the repository at this point in the history
Co-authored-by: Carter Anderson <[email protected]>
  • Loading branch information
TheRawMeatball and cart committed Mar 23, 2021
1 parent 81b53d1 commit 47004df
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 47004df

Please sign in to comment.