pub struct MapStorage<T> { /* private fields */ }
Expand description
A storage type based on a HashMap, intended for sparsely used components.
Implementations§
Source§impl<T> MapStorage<T>
impl<T> MapStorage<T>
Sourcepub fn get(&self, entity: Entity) -> Option<&T>
pub fn get(&self, entity: Entity) -> Option<&T>
Get a reference to the associated component for the given entity, 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 associated component for the given entity, 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(NoSuchEnitty) if the given entity doesn’t exist. Otherwise, returns the previous data stored in self for the given entity.
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.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for MapStorage<T>
impl<T> RefUnwindSafe for MapStorage<T>where
T: RefUnwindSafe,
impl<T> Send for MapStorage<T>where
T: Send,
impl<T> Sync for MapStorage<T>where
T: Sync,
impl<T> Unpin for MapStorage<T>where
T: Unpin,
impl<T> UnwindSafe for MapStorage<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more