1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/// An archetype identifier.
pub type ArchetypeId = u32;
/// An entity identifier within an archetype.
pub type ArchEntityId = u32;

/// An entity identifier.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct EntityId {
    pub archetype_id: ArchetypeId,
    pub id: ArchEntityId,
}

impl EntityId {
    pub const NULL: Self = EntityId {
        archetype_id: u32::MAX,
        id: u32::MAX,
    };

    /// Constructs a new entity identifier.
    pub fn new(archetype_id: ArchetypeId, id: ArchEntityId) -> EntityId {
        EntityId { archetype_id, id }
    }
}

impl Default for EntityId {
    fn default() -> Self {
        EntityId::NULL
    }
}