1#![allow(unused_macros)]
2
3
4#[macro_export]
5macro_rules! format_hex {
6 ($a: expr) => {
7 format!("{:0width$x}", $a, width = 64)
8 };
9
10 ($a: expr, $b: expr) => {
11 format!("{:0width$x}{:0width$x}", $a, $b, width = 64)
12 };
13
14 ($a: expr, $($b: tt)*) => {
15 format!("{:0width$x}{}", $a, format_hex!($($b)*), width = 64)
16 }
17}
18
19#[macro_export]
20macro_rules! forward_val_val_binop {
21 (impl $imp:ident for $res:ty, $method:ident) => {
22 impl $imp<$res> for $res {
23 type Output = $res;
24
25 #[inline]
26 fn $method(self, other: $res) -> $res {
27 $imp::$method(self, &other)
28 }
29 }
30 };
31}
32
33
34#[macro_export]
35macro_rules! forward_ref_val_binop {
36 (impl $imp:ident for $res:ty, $method:ident) => {
37 impl<'a> $imp<$res> for &'a $res {
38 type Output = $res;
39
40 #[inline]
41 fn $method(self, other: $res) -> $res {
42 $imp::$method(self, &other)
43 }
44 }
45 };
46}
47
48#[macro_export]
49macro_rules! forward_val_ref_binop {
50 (impl $imp:ident for $res:ty, $method:ident) => {
51 impl<'a> $imp<&'a $res> for $res {
52 type Output = $res;
53
54 #[inline]
55 fn $method(self, other: &$res) -> $res {
56 $imp::$method(&self, other)
57 }
58 }
59 };
60}
61
62#[macro_export]
63macro_rules! forward_ref_ref_binop {
64 (impl $imp:ident for $res:ty, $method:ident) => {
65 impl<'a, 'b> $imp<&'b $res> for &'a $res {
66 type Output = $res;
67
68 #[inline]
69 fn $method(self, other: &$res) -> $res {
70 $imp::$method(self.clone(), other)
71 }
72 }
73 };
74}
75
76