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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
pub trait EntityRef: Copy + Eq {
fn new(_: usize) -> Self;
fn index(self) -> usize;
}
#[macro_export]
macro_rules! entity_impl {
($entity:ident) => {
impl $crate::entity::EntityRef for $entity {
fn new(index: usize) -> Self {
debug_assert!(index < ($crate::lib::std::u32::MAX as usize));
$entity(index as u32)
}
fn index(self) -> usize {
self.0 as usize
}
}
impl $crate::entity::packed_option::ReservedValue for $entity {
fn reserved_value() -> $entity {
$entity($crate::lib::std::u32::MAX)
}
fn is_reserved_value(&self) -> bool {
self.0 == $crate::lib::std::u32::MAX
}
}
impl $entity {
#[allow(dead_code)]
pub fn from_u32(x: u32) -> Self {
debug_assert!(x < $crate::lib::std::u32::MAX);
$entity(x)
}
#[allow(dead_code)]
pub fn as_u32(self) -> u32 {
self.0
}
}
};
($entity:ident, $display_prefix:expr) => {
entity_impl!($entity);
impl $crate::lib::std::fmt::Display for $entity {
fn fmt(
&self,
f: &mut $crate::lib::std::fmt::Formatter,
) -> $crate::lib::std::fmt::Result {
write!(f, concat!($display_prefix, "{}"), self.0)
}
}
impl $crate::lib::std::fmt::Debug for $entity {
fn fmt(
&self,
f: &mut $crate::lib::std::fmt::Formatter,
) -> $crate::lib::std::fmt::Result {
(self as &dyn $crate::lib::std::fmt::Display).fmt(f)
}
}
};
}
pub mod packed_option;
mod boxed_slice;
mod iter;
mod keys;
mod primary_map;
mod secondary_map;
pub use crate::entity_impl;
pub use boxed_slice::BoxedSlice;
pub use iter::{Iter, IterMut};
pub use keys::Keys;
pub use primary_map::PrimaryMap;
pub use secondary_map::SecondaryMap;