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
28 ($name:ident, $target:ty, $debug: expr) => {
29 $crate::custom_type!(#[doc=""], $name, $target, "{:?}");
30 };
31
32 ($name:ident, $target:ty) => {
33 $crate::custom_type!($name, $target, "{:?}")
34 };
35
36
37}