pub struct Components<T> { /* private fields */ }Expand description
Holds components of a given type indexed by Entity.
We do not check if the given entity is alive here, this should be done using
Entities.
Implementations§
Source§impl<T> Components<T>
impl<T> Components<T>
Sourcepub fn insert(&mut self, entity: Entity, component: T) -> Option<T>
pub fn insert(&mut self, entity: Entity, component: T) -> Option<T>
Inserts a component for the given Entity index.
Returns the previous component, if any.
Sourcepub fn get(&self, entity: Entity) -> Option<&T>
pub fn get(&self, entity: Entity) -> Option<&T>
Gets an immutable reference to the component of Entity.
Sourcepub fn get_mut(&mut self, entity: Entity) -> Option<&mut T>
pub fn get_mut(&mut self, entity: Entity) -> Option<&mut T>
Gets a mutable reference to the component of Entity.
Sourcepub fn remove(&mut self, entity: Entity) -> Option<T>
pub fn remove(&mut self, entity: Entity) -> Option<T>
Removes the component of Entity.
Returns Some(T) if the entity did have the component.
Returns None if the entity did not have the component.
Sourcepub fn iter<'a>(&'a self) -> impl Iterator<Item = &'a T>
pub fn iter<'a>(&'a self) -> impl Iterator<Item = &'a T>
Iterates immutably over all components of this type. Very fast but doesn’t allow joining with other component types.
Sourcepub fn iter_mut<'a>(&'a mut self) -> impl Iterator<Item = &'a mut T>
pub fn iter_mut<'a>(&'a mut self) -> impl Iterator<Item = &'a mut T>
Iterates mutably over all components of this type. Very fast but doesn’t allow joining with other component types.
Sourcepub fn iter_with_bitset<'a>(
&'a self,
bitset: Rc<BitSetVec>,
) -> ComponentIterator<'a, T> ⓘ
pub fn iter_with_bitset<'a>( &'a self, bitset: Rc<BitSetVec>, ) -> ComponentIterator<'a, T> ⓘ
Iterates immutably over the components of this type where bitset
indicates the indices of entities.
Slower than iter() but allows joining between multiple component types.
Sourcepub fn iter_mut_with_bitset<'a>(
&'a mut self,
bitset: Rc<BitSetVec>,
) -> ComponentIteratorMut<'a, T> ⓘ
pub fn iter_mut_with_bitset<'a>( &'a mut self, bitset: Rc<BitSetVec>, ) -> ComponentIteratorMut<'a, T> ⓘ
Iterates mutable over the components of this type where bitset
indicates the indices of entities.
Slower than iter() but allows joining between multiple component types.
Sourcepub fn bitset(&self) -> &BitSetVec
pub fn bitset(&self) -> &BitSetVec
Returns the bitset indicating which entity indices have a component
associated to them.
Useful to build conditions between multiple Components’ bitsets.
For example, take two bitsets from two different Components types.
Then, bitset1.clone().bit_and(bitset2);
And finally, you can use bitset1 in iter_with_bitset and iter_mut_with_bitset.
This will iterate over the components of the entity only for entities that have both
components.