1use std::fmt;
2
3macro_rules! define_id {
4 ($(#[$meta:meta])* $name:ident) => {
5 $(#[$meta])*
6 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
7 pub struct $name(u64);
8
9 impl $name {
10 pub const fn new(raw: u64) -> Self {
11 Self(raw)
12 }
13
14 pub const fn get(self) -> u64 {
15 self.0
16 }
17 }
18
19 impl From<u64> for $name {
20 fn from(value: u64) -> Self {
21 Self::new(value)
22 }
23 }
24
25 impl From<$name> for u64 {
26 fn from(value: $name) -> Self {
27 value.get()
28 }
29 }
30
31 impl fmt::Display for $name {
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 write!(f, "{}", self.0)
34 }
35 }
36 };
37}
38
39define_id!(WidgetId);
40define_id!(
41 WindowId
48);
49define_id!(SurfaceId);
50define_id!(ImageHandle);
51define_id!(FontHandle);
52define_id!(TimerToken);
53define_id!(AsyncWakeToken);