Struct bones_render::prelude::ComponentStore
source · pub struct ComponentStore<T>where
T: TypedEcsData,{ /* private fields */ }Expand description
A typed wrapper around UntypedComponentStore.
Implementations§
source§impl<T> ComponentStore<T>where
T: TypedEcsData + Pod,
impl<T> ComponentStore<T>where
T: TypedEcsData + Pod,
sourcepub fn from_components(components: UntypedComponentStore) -> ComponentStore<T>
pub fn from_components(components: UntypedComponentStore) -> ComponentStore<T>
Create a new ComponentStore<T> by wrapping an UntypedComponentStore.
This method is safe because T is required to implement [Pod], which means T is valid
for any bit pattern.
Panics
This will panic if the layout of T does not match the layout of components.
source§impl<T> ComponentStore<T>where
T: TypedEcsData,
impl<T> ComponentStore<T>where
T: TypedEcsData,
sourcepub unsafe fn from_components_unsafe(
components: UntypedComponentStore
) -> ComponentStore<T>
pub unsafe fn from_components_unsafe(
components: UntypedComponentStore
) -> ComponentStore<T>
Create a new ComponentStore<T> by wrapping an UntypedComponentStore.
Safety
The data stored in components data must be a valid bit pattern for the given type T.
Note: If
Timplements [Pod] you can safely create an instance ofComponentStorewithfrom_components.
sourcepub fn into_untyped(self) -> UntypedComponentStore
pub fn into_untyped(self) -> UntypedComponentStore
Converts to the internal, untyped ComponentStore.
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(&self) -> impl Iterator<Item = &T>
pub fn iter(&self) -> impl Iterator<Item = &T>
Iterates immutably over all components of this type. Very fast but doesn’t allow joining with other component types.
sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &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(
&self,
bitset: Rc<BitSetVec>
) -> ComponentBitsetIterator<'_, T> ⓘ
pub fn iter_with_bitset(
&self,
bitset: Rc<BitSetVec>
) -> ComponentBitsetIterator<'_, 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(
&mut self,
bitset: Rc<BitSetVec>
) -> ComponentBitsetIteratorMut<'_, T> ⓘ
pub fn iter_mut_with_bitset(
&mut self,
bitset: Rc<BitSetVec>
) -> ComponentBitsetIteratorMut<'_, 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.