cxmr-balances 0.0.1

Price and rate traits.
Documentation
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
    }
}