pub trait Storage: Sized {
fn len(&self) -> usize;
fn len_mut(&mut self) -> &mut usize;
fn id(&self) -> StorageId;
fn empty(id: StorageId) -> EmptyStorage<Self>;
unsafe fn component<C: Component>(&self) -> &[C] ⓘ;
unsafe fn component_mut<C: Component>(&self) -> &mut [C] ⓘ;
fn push_components<C, I>(&mut self, components: I)
where
C: Component,
I: IntoIterator<Item = C>;
fn push_component<C: Component>(&mut self, component: C);
fn contains<C: Component>(&self) -> bool;
fn types(&self) -> &HashSet<TypeId>;
fn remove(&mut self, id: ComponentId) -> usize;
}
Expand description
Storage
allows to abstract over different types of storages. The most common storage that
implements this trait is SoaStorage
.
Required Methods§
fn len(&self) -> usize
fn len_mut(&mut self) -> &mut usize
fn id(&self) -> StorageId
sourcefn empty(id: StorageId) -> EmptyStorage<Self>
fn empty(id: StorageId) -> EmptyStorage<Self>
Creates an EmptyStorage
. This storage will not have any registered components when it
is created. See RegisterComponent
.
sourceunsafe fn component<C: Component>(&self) -> &[C] ⓘ
unsafe fn component<C: Component>(&self) -> &[C] ⓘ
Retrieves the component array and panics if C
is not inside this storage.
sourceunsafe fn component_mut<C: Component>(&self) -> &mut [C] ⓘ
unsafe fn component_mut<C: Component>(&self) -> &mut [C] ⓘ
Same as Storage::component
but mutable.
sourcefn push_components<C, I>(&mut self, components: I)where
C: Component,
I: IntoIterator<Item = C>,
fn push_components<C, I>(&mut self, components: I)where
C: Component,
I: IntoIterator<Item = C>,
Appends components to one array. See AppendComponents
that uses this method.
fn push_component<C: Component>(&mut self, component: C)
fn types(&self) -> &HashSet<TypeId>
sourcefn remove(&mut self, id: ComponentId) -> usize
fn remove(&mut self, id: ComponentId) -> usize
Removes all the components at the specified index.