Components

Struct Components 

Source
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>

Source

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.

Source

pub fn get(&self, entity: Entity) -> Option<&T>

Gets an immutable reference to the component of Entity.

Source

pub fn get_mut(&mut self, entity: Entity) -> Option<&mut T>

Gets a mutable reference to the component of Entity.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<T: 'static> Default for Components<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.