Skip to main content

moirai/component/
options.rs

1/// Where registered component data is stored in the world.
2#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
3pub enum StorageKind {
4    /// Per-entity sparse set; default for tags and ordinary data components today.
5    Sparse,
6    /// Archetype column storage for table-backed components (Phase 3).
7    Table,
8}
9
10/// Registration-time storage layout and tag policy for one component type.
11#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
12pub struct ComponentOptions {
13    storage: StorageKind,
14    is_tag: bool,
15}
16
17impl ComponentOptions {
18    /// Default sparse-set storage for ordinary data components.
19    pub const fn sparse() -> Self {
20        Self {
21            storage: StorageKind::Sparse,
22            is_tag: false,
23        }
24    }
25
26    /// Archetype column storage for data components (Phase 3 table backend).
27    pub const fn table() -> Self {
28        Self {
29            storage: StorageKind::Table,
30            is_tag: false,
31        }
32    }
33
34    /// Zero-sized marker component stored in sparse sets.
35    pub const fn tag() -> Self {
36        Self {
37            storage: StorageKind::Sparse,
38            is_tag: true,
39        }
40    }
41
42    #[cfg(test)]
43    pub(crate) const fn test_tag_table() -> Self {
44        Self {
45            storage: StorageKind::Table,
46            is_tag: true,
47        }
48    }
49
50    pub(crate) fn storage(self) -> StorageKind {
51        self.storage
52    }
53
54    pub(crate) fn is_tag(self) -> bool {
55        self.is_tag
56    }
57}