cxmr_balances/
reverse.rs

1use std::cmp::Ordering;
2
3use super::{price, IntoPoints, IntoPrice};
4
5/// Reverse ordered rate.
6/// Highest is the first one.
7#[derive(Copy, Clone, Eq, Deserialize, Serialize, Debug)]
8pub struct ReverseRate(pub u64);
9
10impl Ord for ReverseRate {
11    fn cmp(&self, other: &ReverseRate) -> Ordering {
12        match self.0.cmp(&other.0) {
13            Ordering::Less => Ordering::Greater,
14            Ordering::Greater => Ordering::Less,
15            Ordering::Equal => Ordering::Equal,
16        }
17    }
18}
19
20impl IntoPoints for ReverseRate {
21    #[inline(always)]
22    fn into_points(self) -> u64 {
23        self.0
24    }
25}
26
27impl IntoPrice for ReverseRate {
28    #[inline(always)]
29    fn into_price(self) -> f64 {
30        price(self.0)
31    }
32}
33
34impl PartialOrd for ReverseRate {
35    fn partial_cmp(&self, other: &ReverseRate) -> Option<Ordering> {
36        Some(self.cmp(other))
37    }
38}
39
40impl PartialEq for ReverseRate {
41    fn eq(&self, other: &ReverseRate) -> bool {
42        self.0 == other.0
43    }
44}
45
46impl From<u64> for ReverseRate {
47    fn from(r: u64) -> ReverseRate {
48        ReverseRate(r)
49    }
50}
51
52impl Into<u64> for ReverseRate {
53    #[inline(always)]
54    fn into(self) -> u64 {
55        self.0
56    }
57}
58
59impl Into<u64> for &ReverseRate {
60    #[inline(always)]
61    fn into(self) -> u64 {
62        self.0
63    }
64}