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<Vec<[u32; 8]>>,
) -> ComponentIterator<'a, T> ⓘ
pub fn iter_with_bitset<'a>( &'a self, bitset: Rc<Vec<[u32; 8]>>, ) -> 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<Vec<[u32; 8]>>,
) -> ComponentIteratorMut<'a, T> ⓘ
pub fn iter_mut_with_bitset<'a>( &'a mut self, bitset: Rc<Vec<[u32; 8]>>, ) -> 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) -> &Vec<[u32; 8]>
pub fn bitset(&self) -> &Vec<[u32; 8]>
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.
Trait Implementations§
Source§impl<T> Default for Components<T>where
T: 'static,
impl<T> Default for Components<T>where
T: 'static,
Source§fn default() -> Components<T>
fn default() -> Components<T>
Auto Trait Implementations§
impl<T> Freeze for Components<T>
impl<T> RefUnwindSafe for Components<T>where
T: RefUnwindSafe,
impl<T> Send for Components<T>where
T: Send,
impl<T> Sync for Components<T>where
T: Sync,
impl<T> Unpin for Components<T>where
T: Unpin,
impl<T> UnwindSafe for Components<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more