entity_component/entity.rs
1/// An entity index.
2/// They are created using the `Entities` struct.
3/// They are used as indices with `Components` structs.
4///
5/// Entities are conceptual "things" which possess attributes (Components).
6/// As an exemple, a Car (Entity) has a Color (Component), a Position
7/// (Component) and a Speed (Component).
8#[cfg_attr(feature = "ser", derive(Serialize, Deserialize))]
9#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
10pub struct Entity(u32, u32);
11impl Entity {
12 /// Creates a new `Entity` from the provided index and generation.
13 pub(crate) fn new(index: u32, generation: u32) -> Entity {
14 Entity(index, generation)
15 }
16
17 /// Returns the index of this `Entity`.
18 ///
19 /// In most cases, you do not want to use this directly.
20 /// However, it can be useful to create caches to improve performances.
21 pub fn index(&self) -> u32 {
22 self.0
23 }
24
25 /// Returns the generation of this `Entity`.
26 ///
27 ///
28 /// In most cases, you do not want to use this directly.
29 /// However, it can be useful to create caches to improve performances.
30 pub fn generation(&self) -> u32 {
31 self.1
32 }
33}