Struct bones_lib::prelude::ComponentStore
pub struct ComponentStore<T>where
T: HasSchema,{ /* private fields */ }
Expand description
A typed wrapper around UntypedComponentStore
.
Implementations§
§impl<T> ComponentStore<T>where
T: HasSchema,
impl<T> ComponentStore<T>where
T: HasSchema,
pub fn into_untyped(self) -> UntypedComponentStore
pub fn into_untyped(self) -> UntypedComponentStore
Converts to the internal, untyped ComponentStore
.
pub fn from_untyped(untyped: UntypedComponentStore) -> ComponentStore<T>
pub fn from_untyped(untyped: UntypedComponentStore) -> ComponentStore<T>
Creates a ComponentStore
from an UntypedComponentStore
.
§Panics
Panics if the schema doesn’t match T
.
pub 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.
pub fn get(&self, entity: Entity) -> Option<&T>
pub fn get(&self, entity: Entity) -> Option<&T>
Gets an immutable reference to the component of Entity
.
pub 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
.
pub fn get_mut_or_insert(
&mut self,
entity: Entity,
f: impl FnOnce() -> T,
) -> &mut T
pub fn get_mut_or_insert( &mut self, entity: Entity, f: impl FnOnce() -> T, ) -> &mut T
Get a mutable reference to component if it exists.
Otherwise inserts T
generated by calling parameter: f
.
pub fn get_many_mut<const N: usize>(
&mut self,
entities: [Entity; N],
) -> [Option<&mut T>; N]
pub fn get_many_mut<const N: usize>( &mut self, entities: [Entity; N], ) -> [Option<&mut T>; N]
Get mutable references to the component data for multiple entities at the same time.
§Panics
This will panic if the same entity is specified multiple times. This is invalid because it would mean you would have two mutable references to the same component data at the same time.
pub 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.
pub fn get_single_with_bitset(
&self,
bitset: Rc<BitSetVec>,
) -> Result<&T, QuerySingleError>
pub fn get_single_with_bitset( &self, bitset: Rc<BitSetVec>, ) -> Result<&T, QuerySingleError>
Gets an immutable reference to the component if there is exactly one instance of it.
pub fn get_single_with_bitset_mut(
&mut self,
bitset: Rc<BitSetVec>,
) -> Result<&mut T, QuerySingleError>
pub fn get_single_with_bitset_mut( &mut self, bitset: Rc<BitSetVec>, ) -> Result<&mut T, QuerySingleError>
Gets a mutable reference to the component if there is exactly one instance of it.
Trait Implementations§
§impl<T> Clone for ComponentStore<T>
impl<T> Clone for ComponentStore<T>
§fn clone(&self) -> ComponentStore<T>
fn clone(&self) -> ComponentStore<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl<'a, T> ComponentIterBitset<'a, T> for ComponentStore<T>where
T: HasSchema,
impl<'a, T> ComponentIterBitset<'a, T> for ComponentStore<T>where
T: HasSchema,
§fn get_single_with_bitset(
&self,
bitset: Rc<BitSetVec>,
) -> Result<&T, QuerySingleError>
fn get_single_with_bitset( &self, bitset: Rc<BitSetVec>, ) -> Result<&T, QuerySingleError>
Gets an immutable reference to the component if there is exactly one instance of it.
§fn get_single_mut_with_bitset(
&mut self,
bitset: Rc<BitSetVec>,
) -> Result<&mut T, QuerySingleError>
fn get_single_mut_with_bitset( &mut self, bitset: Rc<BitSetVec>, ) -> Result<&mut T, QuerySingleError>
Gets a mutable reference to the component if there is exactly one instance of it.
§fn iter_with_bitset(
&self,
bitset: Rc<BitSetVec>,
) -> Map<UntypedComponentBitsetIterator<'_>, for<'b> fn(_: SchemaRef<'b>) -> &'b T> ⓘ
fn iter_with_bitset( &self, bitset: Rc<BitSetVec>, ) -> Map<UntypedComponentBitsetIterator<'_>, for<'b> fn(_: SchemaRef<'b>) -> &'b 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.
§fn iter_with_bitset_optional(
&self,
bitset: Rc<BitSetVec>,
) -> Map<UntypedComponentOptionalBitsetIterator<'_>, for<'b> fn(_: Option<SchemaRef<'b>>) -> Option<&'b T>> ⓘ
fn iter_with_bitset_optional( &self, bitset: Rc<BitSetVec>, ) -> Map<UntypedComponentOptionalBitsetIterator<'_>, for<'b> fn(_: Option<SchemaRef<'b>>) -> Option<&'b T>> ⓘ
Iterates immutably over the components of this type where bitset
indicates the indices of entities where iterator returns an Option.
None is returned for entities in bitset when Component is not in ComponentStore
§fn iter_mut_with_bitset(
&mut self,
bitset: Rc<BitSetVec>,
) -> Map<UntypedComponentBitsetIteratorMut<'_>, for<'b> fn(_: SchemaRefMut<'b>) -> &'b mut T> ⓘ
fn iter_mut_with_bitset( &mut self, bitset: Rc<BitSetVec>, ) -> Map<UntypedComponentBitsetIteratorMut<'_>, for<'b> fn(_: SchemaRefMut<'b>) -> &'b mut 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.
§fn iter_mut_with_bitset_optional(
&mut self,
bitset: Rc<BitSetVec>,
) -> Map<UntypedComponentOptionalBitsetIteratorMut<'_>, for<'b> fn(_: Option<SchemaRefMut<'b>>) -> Option<&'b mut T>> ⓘ
fn iter_mut_with_bitset_optional( &mut self, bitset: Rc<BitSetVec>, ) -> Map<UntypedComponentOptionalBitsetIteratorMut<'_>, for<'b> fn(_: Option<SchemaRefMut<'b>>) -> Option<&'b mut T>> ⓘ
Iterates mutably over the components of this type where bitset
indicates the indices of entities where iterator returns an Option.
None is returned for entities in bitset when Component is not in [ComponentStore
§fn bitset(&self) -> &BitSetVec
fn bitset(&self) -> &BitSetVec
Read the bitset containing the list of entites with this component type on it.
§fn contains(&self, entity: Entity) -> bool
fn contains(&self, entity: Entity) -> bool
Check whether or not this component store has data for the given entity.
§fn component_store(&self) -> &ComponentStore<T>
fn component_store(&self) -> &ComponentStore<T>
ComponentStore
for usage with generic types implementing ComponentIterBitset
.§impl<T> Default for ComponentStore<T>where
T: HasSchema,
impl<T> Default for ComponentStore<T>where
T: HasSchema,
§fn default() -> ComponentStore<T>
fn default() -> ComponentStore<T>
§impl<T> TryFrom<UntypedComponentStore> for ComponentStore<T>where
T: HasSchema,
impl<T> TryFrom<UntypedComponentStore> for ComponentStore<T>where
T: HasSchema,
§type Error = SchemaMismatchError
type Error = SchemaMismatchError
§fn try_from(
untyped: UntypedComponentStore,
) -> Result<ComponentStore<T>, <ComponentStore<T> as TryFrom<UntypedComponentStore>>::Error>
fn try_from( untyped: UntypedComponentStore, ) -> Result<ComponentStore<T>, <ComponentStore<T> as TryFrom<UntypedComponentStore>>::Error>
Auto Trait Implementations§
impl<T> Freeze for ComponentStore<T>
impl<T> !RefUnwindSafe for ComponentStore<T>
impl<T> Send for ComponentStore<T>
impl<T> Sync for ComponentStore<T>
impl<T> Unpin for ComponentStore<T>where
T: Unpin,
impl<T> !UnwindSafe for ComponentStore<T>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
§fn from_world(_world: &World) -> T
fn from_world(_world: &World) -> T
Self
using data from the given World
.