Skip to main content

rdif_def/
_macro.rs

1#[macro_export]
2macro_rules! custom_type {
3    ($(#[$doc:meta])*, $name:ident, $target:ty, $debug: expr) => {
4        #[derive(Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
5        #[repr(transparent)]
6        $(#[$doc])*
7        pub struct $name($target);
8
9        impl From<$target> for $name {
10            fn from(value: $target) -> Self {
11                Self(value)
12            }
13        }
14
15        impl From<$name> for $target {
16            fn from(value: $name) -> Self {
17                value.0
18            }
19        }
20
21        impl core::fmt::Debug for $name {
22            fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
23                write!(f, $debug, self.0)
24            }
25        }
26
27        impl $name {
28            pub fn raw(&self) -> $target {
29                self.0
30            }
31        }
32    };
33
34    ($name:ident, $target:ty, $debug: expr) => {
35        $crate::custom_type!(#[doc=""], $name, $target, "{:?}");
36    };
37
38    ($name:ident, $target:ty) => {
39        $crate::custom_type!($name, $target, "{:?}")
40    };
41
42
43}