pub struct VecStorage<T> { /* private fields */ }Expand description
A storage type that stores components in a contiguous Vec
Implementations§
Source§impl<T> VecStorage<T>
impl<T> VecStorage<T>
Sourcepub fn new(entities: Arc<RwLock<Entities>>, capacity: u32) -> Self
pub fn new(entities: Arc<RwLock<Entities>>, capacity: u32) -> Self
Create a new VecStorage
Sourcepub fn get(&self, entity: Entity) -> Option<&T>
pub fn get(&self, entity: Entity) -> Option<&T>
Get a reference to the component associated with the given entity in self, if any.
Sourcepub fn get_mut(&mut self, entity: Entity) -> Option<&mut T>
pub fn get_mut(&mut self, entity: Entity) -> Option<&mut T>
Get a mutable reference to the component associated with the given entity in self, if any.
Sourcepub fn set(
&mut self,
entity: Entity,
data: T,
) -> Result<Option<T>, NoSuchEntity>
pub fn set( &mut self, entity: Entity, data: T, ) -> Result<Option<T>, NoSuchEntity>
Set the component for the given entity. Returns Err(NoSuchEntity) if the given entity doesn’t exist. Otherwise, returns Ok(data), where data is previous data evicted by this operation (if any).
Sourcepub fn remove_unchecked(&mut self, entity: Entity) -> Option<T>
pub fn remove_unchecked(&mut self, entity: Entity) -> Option<T>
Remove the component for the given entity. Returns the previous data associated with the given entity in self. Does not check if the entity exists; only use this if you know it exists, e.g. through invariants in your code or because you retrieved this in a loop iterating over all alive entities.