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