driver_interface/
_macro.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#[macro_export]
macro_rules! custom_type {
    ($name:ident, $target:ty, $debug: expr) => {
        #[derive(Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
        #[repr(transparent)]
        pub struct $name($target);

        impl From<$target> for $name {
            fn from(value: $target) -> Self {
                Self(value)
            }
        }

        impl From<$name> for $target {
            fn from(value: $name) -> Self {
                value.0
            }
        }

        impl Debug for $name {
            fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
                write!(f, $debug, self.0)
            }
        }
    };

    ($name:ident, $target:ty) => {
        $crate::custom_type!($name, $target, "{:?}")
    };
}