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_vec;
24mod resource;
25mod sparse_set;
26mod table;
27
28pub use resource::*;
29pub use sparse_set::*;
30pub use table::*;
31
32/// The raw data stores of a [`World`](crate::world::World)
33#[derive(Default)]
34pub struct Storages {
35 /// Backing storage for [`SparseSet`] components.
36 pub sparse_sets: SparseSets,
37 /// Backing storage for [`Table`] components.
38 pub tables: Tables,
39 /// Backing storage for resources.
40 pub resources: Resources<true>,
41 /// Backing storage for `!Send` resources.
42 pub non_send_resources: Resources<false>,
43}