stm32f1_hal/common/
wrap_trait.rs

1#![allow(unused_macros)]
2#![allow(unused_imports)]
3
4pub use core::ops::Deref;
5
6macro_rules! impl_wrap_func {
7    (fn $func:ident(&$($life:lifetime)? self $(, $arg:ident: $arg_ty:ty)*) $(-> $ret:ty)?; $($rest_func:tt)*) => {
8        #[inline(always)]
9        fn $func(&$($life)? self $(, $arg: $arg_ty),*) $(-> $ret)? {
10            self.$func($($arg),*)
11        }
12        impl_wrap_func!($($rest_func)*);
13    };
14    (fn $func:ident(&$($life:lifetime)? mut self $(, $arg:ident: $arg_ty:ty)*) $(-> $ret:ty)?; $($rest_func:tt)*) => {
15        #[inline(always)]
16        fn $func(&$($life)? mut self $(, $arg: $arg_ty),*) $(-> $ret)? {
17             self.$func($($arg),*)
18        }
19        impl_wrap_func!($($rest_func)*);
20    };
21    () => {};
22}
23pub(crate) use impl_wrap_func;
24
25macro_rules! impl_wrap_func_deref {
26    (fn $func:ident(&$($life:lifetime)? self $(, $arg:ident: $arg_ty:ty)*) $(-> $ret:ty)?; $($rest_func:tt)*) => {
27        #[inline(always)]
28        fn $func(&$($life)? self $(, $arg: $arg_ty),*) $(-> $ret)? {
29            self.deref().$func($($arg),*)
30        }
31        impl_wrap_func_deref!($($rest_func)*);
32    };
33    (fn $func:ident(&$($life:lifetime)? mut self $(, $arg:ident: $arg_ty:ty)*) $(-> $ret:ty)?; $($rest_func:tt)*) => {
34        #[inline(always)]
35        fn $func(&$($life)? mut self $(, $arg: $arg_ty),*) $(-> $ret)? {
36            self.deref().$func($($arg),*)
37        }
38        impl_wrap_func_deref!($($rest_func)*);
39    };
40    () => {};
41}
42pub(crate) use impl_wrap_func_deref;
43
44macro_rules! impl_wrap_trait {
45    (
46        $vis:vis trait $trait_name:ident $(: $($dep:ty)+)? {
47            $($func:tt)*
48        }
49        $type:ty
50    ) => {
51        impl $trait_name for $type {
52            impl_wrap_func!($($func)*);
53        }
54    };
55}
56pub(crate) use impl_wrap_trait;
57
58macro_rules! impl_wrap_trait_deref {
59    (
60        $vis:vis trait $trait_name:ident $(: $($dep:ty)+)? {
61            $($func:tt)*
62        }
63        $type:ty
64    ) => {
65        impl $trait_name for $type {
66            impl_wrap_func_deref!($($func)*);
67        }
68    };
69}
70pub(crate) use impl_wrap_trait_deref;
71
72macro_rules! wrap_trait {
73    (
74        ($type:ty, $($rest_type:ty,)*),
75        $($trait_body:tt)+
76    ) => {
77        wrap_trait!(($($rest_type,)*), $($trait_body)+);
78        impl_wrap_trait!($($trait_body)+ $type);
79    };
80
81    ((), $($trait_body:tt)+) => {
82        // Declare the trait
83        $($trait_body)+
84    };
85}
86pub(crate) use wrap_trait;
87
88macro_rules! wrap_trait_deref {
89    (
90        ($type:ty, $($rest_type:ty,)*),
91        $($trait_body:tt)+
92    ) => {
93        wrap_trait_deref!(($($rest_type,)*), $($trait_body)+);
94        impl_wrap_trait_deref!($($trait_body)+ $type);
95    };
96
97    ((), $($trait_body:tt)+) => {
98        // Declare the trait
99        $($trait_body)+
100    };
101}
102pub(crate) use wrap_trait_deref;