Trait shipyard::Remove [−][src]
pub trait Remove<T: Removable> {
fn try_remove(self, entity: EntityId) -> Result<T::Out, Remove>;
fn remove(self, entity: EntityId) -> T::Out;
}
Expand description
Removes component from entities.
Required methods
fn try_remove(self, entity: EntityId) -> Result<T::Out, Remove>
fn try_remove(self, entity: EntityId) -> Result<T::Out, Remove>
Removes component in entity
, if the entity had them, they will be returned.
Multiple components can be removed at the same time using a tuple.
T
has to be a tuple even for a single type.
In this case use (T,).
The compiler has trouble inferring the return types.
You’ll often have to use the full path Remove::<type>::try_remove
.
Example
use shipyard::{EntitiesViewMut, Remove, ViewMut, World};
let world = World::new();
world.run(|mut entities: EntitiesViewMut, mut usizes: ViewMut<usize>, mut u32s: ViewMut<u32>| {
let entity1 = entities.add_entity((&mut usizes, &mut u32s), (0usize, 1u32));
let old = Remove::<(usize, u32)>::try_remove((&mut usizes, &mut u32s), entity1).unwrap();
assert_eq!(old, (Some(0), Some(1)));
});
When using packed storages you have to pass all storages packed with it, even if you don’t remove any component from it.
Example
use shipyard::{EntitiesViewMut, Remove, TightPack, ViewMut, World};
let world = World::new();
world.run(|mut entities: EntitiesViewMut, mut usizes: ViewMut<usize>, mut u32s: ViewMut<u32>| {
(&mut usizes, &mut u32s).tight_pack();
let entity1 = entities.add_entity((&mut usizes, &mut u32s), (0usize, 1u32));
let old = Remove::<(usize,)>::try_remove((&mut usizes, &mut u32s), entity1).unwrap();
assert_eq!(old, (Some(0),));
});
Removes component in entity
, if the entity had them, they will be returned.
Multiple components can be removed at the same time using a tuple.
T
has to be a tuple even for a single type.
In this case use (T,).
The compiler has trouble inferring the return types.
You’ll often have to use the full path Remove::<type>::remove
.
Unwraps errors.
Example
use shipyard::{EntitiesViewMut, Remove, ViewMut, World};
let world = World::new();
world.run(|mut entities: EntitiesViewMut, mut usizes: ViewMut<usize>, mut u32s: ViewMut<u32>| {
let entity1 = entities.add_entity((&mut usizes, &mut u32s), (0usize, 1u32));
let old = Remove::<(usize, u32)>::remove((&mut usizes, &mut u32s), entity1);
assert_eq!(old, (Some(0), Some(1)));
});
When using packed storages you have to pass all storages packed with it, even if you don’t remove any component from it.
Example
use shipyard::{EntitiesViewMut, Remove, TightPack, ViewMut, World};
let world = World::new();
world.run(|mut entities: EntitiesViewMut, mut usizes: ViewMut<usize>, mut u32s: ViewMut<u32>| {
(&mut usizes, &mut u32s).tight_pack();
let entity1 = entities.add_entity((&mut usizes, &mut u32s), (0usize, 1u32));
let old = Remove::<(usize,)>::remove((&mut usizes, &mut u32s), entity1);
assert_eq!(old, (Some(0),));
});