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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use std::cmp::Ordering;

use super::{price, IntoPoints, IntoPrice};

/// Reverse ordered rate.
/// Highest is the first one.
#[derive(Copy, Clone, Eq, Deserialize, Serialize, Debug)]
pub struct ReverseRate(pub u64);

impl Ord for ReverseRate {
    fn cmp(&self, other: &ReverseRate) -> Ordering {
        match self.0.cmp(&other.0) {
            Ordering::Less => Ordering::Greater,
            Ordering::Greater => Ordering::Less,
            Ordering::Equal => Ordering::Equal,
        }
    }
}

impl IntoPoints for ReverseRate {
    #[inline(always)]
    fn into_points(self) -> u64 {
        self.0
    }
}

impl IntoPrice for ReverseRate {
    #[inline(always)]
    fn into_price(self) -> f64 {
        price(self.0)
    }
}

impl PartialOrd for ReverseRate {
    fn partial_cmp(&self, other: &ReverseRate) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

impl PartialEq for ReverseRate {
    fn eq(&self, other: &ReverseRate) -> bool {
        self.0 == other.0
    }
}

impl From<u64> for ReverseRate {
    fn from(r: u64) -> ReverseRate {
        ReverseRate(r)
    }
}

impl Into<u64> for ReverseRate {
    #[inline(always)]
    fn into(self) -> u64 {
        self.0
    }
}

impl Into<u64> for &ReverseRate {
    #[inline(always)]
    fn into(self) -> u64 {
        self.0
    }
}