Struct bones_render::prelude::TypedComponentOps
source · pub struct TypedComponentOps<T>(_);Expand description
Implements typed operations on top of a UntypedComponentStore.
This is a utility used to help represent the unsafty of interpreting the UntypedComponentStore
as a particular type.
It is unsafe to construct a TypedComponentOps to indicate that you are taking responsibility
for only calling it’s functions on an UntypedComponentStore that actually corresponds to the
type T that the TypedComponentOps was created for.
Note: The alternative to this approach would be to make every method of this type
unsafe, which may be a better option. It really seems like a matter of preference, but if you have an opinion, @zicklag would be happy to discuss on GitHub!
Implementations§
source§impl<T> TypedComponentOps<T>where
T: Clone + 'static,
impl<T> TypedComponentOps<T>where
T: Clone + 'static,
sourcepub unsafe fn new() -> TypedComponentOps<T>
pub unsafe fn new() -> TypedComponentOps<T>
Safety
Creating TypedComponentOps must only be used on an UntypedComponentStore where the
underlying, untyped component data is valid for T.
sourcepub fn insert(
&self,
components: &mut UntypedComponentStore,
entity: Entity,
component: T
) -> Option<T>
pub fn insert(
&self,
components: &mut UntypedComponentStore,
entity: Entity,
component: T
) -> Option<T>
Insert a component into the store.
sourcepub fn get(
&self,
components: &UntypedComponentStore,
entity: Entity
) -> Option<&T>
pub fn get(
&self,
components: &UntypedComponentStore,
entity: Entity
) -> Option<&T>
Borrow a component in the store, if it exists for the given entity.
sourcepub fn get_mut(
&self,
components: &mut UntypedComponentStore,
entity: Entity
) -> Option<&mut T>
pub fn get_mut(
&self,
components: &mut UntypedComponentStore,
entity: Entity
) -> Option<&mut T>
Mutably borrow a component in the store, if it exists for the given entity.
sourcepub fn remove(
&self,
components: &mut UntypedComponentStore,
entity: Entity
) -> Option<T>
pub fn remove(
&self,
components: &mut UntypedComponentStore,
entity: Entity
) -> Option<T>
Remove a component from an entity, returning the previous component if one existed.
sourcepub fn iter<'a>(
&'a self,
components: &'a UntypedComponentStore
) -> impl Iterator<Item = &'a T>
pub fn iter<'a>(
&'a self,
components: &'a UntypedComponentStore
) -> impl Iterator<Item = &'a T>
Iterate over all components in the store.
sourcepub fn iter_mut<'a>(
&'a self,
components: &'a mut UntypedComponentStore
) -> impl Iterator<Item = &'a mut T>
pub fn iter_mut<'a>(
&'a self,
components: &'a mut UntypedComponentStore
) -> impl Iterator<Item = &'a mut T>
Mutably iterate over all components in the store.
sourcepub fn iter_with_bitset<'a>(
&'a self,
components: &'a UntypedComponentStore,
bitset: Rc<BitSetVec>
) -> ComponentBitsetIterator<'a, T> ⓘ
pub fn iter_with_bitset<'a>(
&'a self,
components: &'a UntypedComponentStore,
bitset: Rc<BitSetVec>
) -> ComponentBitsetIterator<'a, T> ⓘ
Iterate over all the components in the store that match the entities in the given bitset.
sourcepub fn iter_mut_with_bitset<'a>(
&'a self,
components: &'a mut UntypedComponentStore,
bitset: Rc<BitSetVec>
) -> ComponentBitsetIteratorMut<'a, T> ⓘ
pub fn iter_mut_with_bitset<'a>(
&'a self,
components: &'a mut UntypedComponentStore,
bitset: Rc<BitSetVec>
) -> ComponentBitsetIteratorMut<'a, T> ⓘ
Mutably iterate over all the components in the store that match the entities in the given bitset.