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
33
34
35
36
37
38
39
40
#![macro_use]
macro_rules! impl_newtype_traits {
($type: ty) => {
impl From<$type> for f64 {
fn from(value: $type) -> f64 {
value.0
}
}
impl PartialOrd<$type> for $type {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(&other))
}
}
impl Ord for $type {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
match self.0.partial_cmp(&other.0) {
Some(ordering) => ordering,
None => panic!("invalid f64 snuck in somehow"),
}
}
}
impl PartialEq for $type {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl Eq for $type {}
impl std::fmt::Display for $type {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}({})", stringify!($type), self.0)
}
}
};
}