bevy_ecs/storage/
mod.rs

1//! Storage layouts for ECS data.
2//!
3//! This module implements the low-level collections that store data in a [`World`]. These all offer minimal and often
4//! unsafe APIs, and have been made `pub` primarily for debugging and monitoring purposes.
5//!
6//! # Fetching Storages
7//! Each of the below data stores can be fetched via [`Storages`], which can be fetched from a
8//! [`World`] via [`World::storages`]. It exposes a top level container for each class of storage within
9//! ECS:
10//!
11//!  - [`Tables`] - columnar contiguous blocks of memory, optimized for fast iteration.
12//!  - [`SparseSets`] - sparse `HashMap`-like mappings from entities to components, optimized for random
13//!    lookup and regular insertion/removal of components.
14//!  - [`Resources`] - singleton storage for the resources in the world
15//!
16//! # Safety
17//! To avoid trivially unsound use of the APIs in this module, it is explicitly impossible to get a mutable
18//! reference to [`Storages`] from [`World`], and none of the types publicly expose a mutable interface.
19//!
20//! [`World`]: crate::world::World
21//! [`World::storages`]: crate::world::World::storages
22
23mod blob_array;
24mod blob_vec;
25mod resource;
26mod sparse_set;
27mod table;
28mod thin_array_ptr;
29
30pub use resource::*;
31pub use sparse_set::*;
32pub use table::*;
33
34/// The raw data stores of a [`World`](crate::world::World)
35#[derive(Default)]
36pub struct Storages {
37    /// Backing storage for [`SparseSet`] components.
38    pub sparse_sets: SparseSets,
39    /// Backing storage for [`Table`] components.
40    pub tables: Tables,
41    /// Backing storage for resources.
42    pub resources: Resources<true>,
43    /// Backing storage for `!Send` resources.
44    pub non_send_resources: Resources<false>,
45}