1use std::cmp::Ordering;
2use std::fmt::{Debug, Formatter};
3
4#[derive(PartialOrd, PartialEq)]
5pub struct UncheckOrd<T: PartialOrd + PartialEq>(pub T);
6
7impl<T: PartialOrd + PartialEq> Eq for UncheckOrd<T> {}
8
9impl<T: PartialOrd + PartialEq> Ord for UncheckOrd<T> {
10 fn cmp(&self, other: &Self) -> Ordering {
11 self.0.partial_cmp(&other.0).unwrap()
12 }
13}
14
15impl<T: PartialOrd + PartialEq + Debug> Debug for UncheckOrd<T> {
16 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
17 write!(f, "UncheckOrd({:?})", self.0)
18 }
19}
20
21#[cfg(test)]
22mod tests {
23 use crate::UncheckOrd;
24
25 #[test]
26 fn it_works() {
27 let v = [1.0, 3.0, 2.0];
28 let mut v: Vec<_> = v.iter().copied().map(|x| UncheckOrd(x)).collect();
29
30 v.sort();
31
32 assert_eq!(
33 v,
34 vec![
35 UncheckOrd(1.0_f64),
36 UncheckOrd(2.0_f64),
37 UncheckOrd(3.0_f64)
38 ]
39 );
40 }
41}