ex3_node_types/
util.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
31
32
#[macro_export(local_inner_macros)]
macro_rules! impl_from_uint_for {
    ($to_type:ty, $($t:ty),*) => {
        $(
            impl From<$t> for $to_type {
                fn from(value: $t) -> Self {
                    <$to_type>::from(BigUint::from(value))
                }
            }
        )*
    };
}

#[macro_export(local_inner_macros)]
macro_rules! impl_compare_unit_for {
    ($to_type:ty, $($t:ty),*) => {
        $(

            impl PartialEq<$t> for $to_type {
                fn eq(&self, other: &$t) -> bool {
                    self.0 == BigUint::from(*other)
                }
            }

            impl PartialOrd<$t> for $to_type {
                fn partial_cmp(&self, other: &$t) -> Option<std::cmp::Ordering> {
                    self.0.partial_cmp(&BigUint::from(*other))
                }
            }
        )*
    };
}