userspace/macros/traits/
partial_eq.rs

1#[macro_export]
2macro_rules! trait_implement_partial_eq {
3    ($name:ty, $inner:ty, $($t:ty),*) => {
4        $(
5            impl core::cmp::PartialEq<$t> for $name {
6                fn eq(&self, other: &$t) -> bool {
7                    if (*other as u128) <= <$inner>::MAX as u128 {
8                        self.0 == *other as $inner
9                    } else {
10                        false
11                    }
12                }
13            }
14
15            impl core::cmp::PartialEq<$name> for $t {
16                fn eq(&self, other: &$name) -> bool {
17                    if (*self as u128) <= <$inner>::MAX as u128 {
18                        *self as $inner == other.0
19                    } else {
20                        false
21                    }
22                }
23            }
24
25            impl core::cmp::PartialOrd<$t> for $name {
26                fn partial_cmp(&self, other: &$t) -> Option<core::cmp::Ordering> {
27                    if (*other as u128) <= <$inner>::MAX as u128 {
28                        Some(self.0.cmp(&(*other as $inner)))
29                    } else {
30                        None
31                    }
32                }
33            }
34
35            impl core::cmp::PartialOrd<$name> for $t {
36                fn partial_cmp(&self, other: &$name) -> Option<core::cmp::Ordering> {
37                    if (*self as u128) <= <$inner>::MAX as u128 {
38                        Some((*self as $inner).cmp(&other.0))
39                    } else {
40                        None
41                    }
42                }
43            }
44        )*
45    }
46}
47pub use trait_implement_partial_eq;