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
use std::cmp::{Ordering, PartialOrd};
use std::sync::Arc;
pub fn compare_floats(a: f64, b: f64) -> Ordering {
match (a, b) {
(x, y) if x.is_nan() && y.is_nan() => Ordering::Equal,
(x, _) if x.is_nan() => Ordering::Greater,
(_, y) if y.is_nan() => Ordering::Less,
(_, _) => a.partial_cmp(&b).unwrap(),
}
}
pub fn compare_shared<T: ?Sized>(left: &Arc<T>, right: &Arc<T>) -> bool {
let left: *const T = left.as_ref();
let right: *const T = right.as_ref();
left == right
}
pub fn unwrap_from_result<T>(result: Result<T, T>) -> T {
match result {
Ok(result) => result,
Err(result) => result,
}
}