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