1use std::fmt;
2
3macro_rules! define_id {
4 ($name:ident, $label:literal) => {
5 #[doc = concat!("A stable identifier for an avatar ", $label, ".")]
6 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 pub struct $name(u32);
8
9 impl $name {
10 pub const fn from_index(index: usize) -> Self {
15 Self(index as u32)
16 }
17
18 pub const fn index(self) -> usize {
20 self.0 as usize
21 }
22 }
23
24 impl fmt::Display for $name {
25 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
26 self.0.fmt(formatter)
27 }
28 }
29 };
30}
31
32define_id!(NodeId, "node");
33define_id!(PrimitiveId, "render primitive");
34define_id!(MaterialId, "material");
35define_id!(TextureId, "texture");
36define_id!(ImageId, "image");
37define_id!(SkinId, "skin");