use crate::entity;
mod vec;
pub use vec::VecStorage as Vec;
mod tree;
pub use tree::Tree;
mod simple;
pub(crate) use simple::Simple;
mod isotope;
pub(crate) use isotope::{AnyMap as AnyIsotopeMap, Map as IsotopeMap, MapInner as IsotopeMapInner};
#[cfg(test)]
mod tests;
pub unsafe trait Storage: Default + Send + Sync + 'static {
type RawEntity: entity::Raw;
type Comp;
fn get(&self, id: Self::RawEntity) -> Option<&Self::Comp>;
fn get_mut(&mut self, id: Self::RawEntity) -> Option<&mut Self::Comp>;
fn set(&mut self, id: Self::RawEntity, value: Option<Self::Comp>) -> Option<Self::Comp>;
fn cardinality(&self) -> usize;
type Iter<'t>: Iterator<Item = (Self::RawEntity, &'t Self::Comp)> + 't;
fn iter(&self) -> Self::Iter<'_>;
type IterChunks<'t>: Iterator<Item = ChunkRef<'t, Self>> + 't;
fn iter_chunks(&self) -> Self::IterChunks<'_>;
type IterMut<'t>: Iterator<Item = (Self::RawEntity, &'t mut Self::Comp)> + 't;
fn iter_mut(&mut self) -> Self::IterMut<'_>;
type IterChunksMut<'t>: Iterator<Item = ChunkMut<'t, Self>> + 't;
fn iter_chunks_mut(&mut self) -> Self::IterChunksMut<'_>;
type StoragePartition<'t>: Partition<Self::RawEntity, Self::Comp>
where
Self: 't;
fn partition_at(
&mut self,
offset: Self::RawEntity,
) -> (Self::StoragePartition<'_>, Self::StoragePartition<'_>);
}
pub trait Partition<E: entity::Raw, C>: Sized {
fn get_mut(&mut self, entity: E) -> Option<&mut C>;
type IterMut<'t>: Iterator<Item = (E, &'t mut C)> + 't
where
Self: 't,
C: 't;
fn iter_mut(&mut self) -> Self::IterMut<'_>;
type PartitionAt<'u>: Partition<E, C> + 'u
where
Self: 'u;
fn partition_at(&mut self, entity: E) -> (Self::PartitionAt<'_>, Self::PartitionAt<'_>);
}
pub unsafe trait Chunked: Storage {
fn get_chunk(&self, start: Self::RawEntity, end: Self::RawEntity) -> Option<&[Self::Comp]>;
fn get_chunk_mut(
&mut self,
start: Self::RawEntity,
end: Self::RawEntity,
) -> Option<&mut [Self::Comp]>;
}
pub struct ChunkRef<'t, S: Storage> {
pub slice: &'t [S::Comp],
pub start: S::RawEntity,
}
pub struct ChunkMut<'t, S: Storage> {
pub slice: &'t mut [S::Comp],
pub start: S::RawEntity,
}