//! Storage layouts for ECS data.1//!2//! This module implements the low-level collections that store data in a [`World`]. These all offer minimal and often3//! unsafe APIs, and have been made `pub` primarily for debugging and monitoring purposes.4//!5//! # Fetching Storages6//! Each of the below data stores can be fetched via [`Storages`], which can be fetched from a7//! [`World`] via [`World::storages`]. It exposes a top level container for each class of storage within8//! ECS:9//!10//! - [`Tables`] - columnar contiguous blocks of memory, optimized for fast iteration.11//! - [`SparseSets`] - sparse `HashMap`-like mappings from entities to components, optimized for random12//! lookup and regular insertion/removal of components.13//! - [`Resources`] - singleton storage for the resources in the world14//!15//! # Safety16//! To avoid trivially unsound use of the APIs in this module, it is explicitly impossible to get a mutable17//! reference to [`Storages`] from [`World`], and none of the types publicly expose a mutable interface.18//!19//! [`World`]: crate::world::World20//! [`World::storages`]: crate::world::World::storages2122mod blob_array;23mod blob_vec;24mod resource;25mod sparse_set;26mod table;27mod thin_array_ptr;2829pub use resource::*;30pub use sparse_set::*;31pub use table::*;3233use crate::component::{ComponentInfo, StorageType};3435/// The raw data stores of a [`World`](crate::world::World)36#[derive(Default)]37pub struct Storages {38/// Backing storage for [`SparseSet`] components.39/// Note that sparse sets are only present for components that have been spawned or have had a relevant bundle registered.40pub sparse_sets: SparseSets,41/// Backing storage for [`Table`] components.42pub tables: Tables,43/// Backing storage for resources.44pub resources: Resources<true>,45/// Backing storage for `!Send` resources.46pub non_send_resources: Resources<false>,47}4849impl Storages {50/// ensures that the component has its necessary storage initialize.51pub fn prepare_component(&mut self, component: &ComponentInfo) {52match component.storage_type() {53StorageType::Table => {54// table needs no preparation55}56StorageType::SparseSet => {57self.sparse_sets.get_or_insert(component);58}59}60}61}626364