Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed May 3, 2024
1 parent 76939ab commit decad20
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/vendor/kamino/fraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mod uint_types {

pub use uint_types::{U128, U256};

/*
pub fn pow_fraction(fraction: Fraction, power: u32) -> Option<Fraction> {
if power == 0 {
return Some(Fraction::ONE);
Expand All @@ -38,47 +39,56 @@ pub fn pow_fraction(fraction: Fraction, power: u32) -> Option<Fraction> {
x.checked_mul(y)
}
*/

pub trait FractionExtra {
fn to_percent<Dst: FromFixed>(&self) -> Option<Dst>;
fn to_bps<Dst: FromFixed>(&self) -> Option<Dst>;
fn from_percent<Src: ToFixed>(percent: Src) -> Self;
fn from_bps<Src: ToFixed>(bps: Src) -> Self;
fn to_floor<Dst: FromFixed>(&self) -> Dst;
/*
fn to_percent<Dst: FromFixed>(&self) -> Option<Dst>;
fn from_percent<Src: ToFixed>(percent: Src) -> Self;
fn checked_pow(&self, power: u32) -> Option<Self>
where
Self: std::marker::Sized;
fn to_floor<Dst: FromFixed>(&self) -> Dst;
fn to_ceil<Dst: FromFixed>(&self) -> Dst;
fn to_round<Dst: FromFixed>(&self) -> Dst;
fn to_sf(&self) -> u128;
fn from_sf(sf: u128) -> Self;
fn to_display(&self) -> FractionDisplay;
*/
}

impl FractionExtra for Fraction {
#[inline]
fn to_percent<Dst: FromFixed>(&self) -> Option<Dst> {
(self * 100).round().checked_to_num()
fn to_bps<Dst: FromFixed>(&self) -> Option<Dst> {
(self * 10_000).round().checked_to_num()
}

#[inline]
fn to_bps<Dst: FromFixed>(&self) -> Option<Dst> {
(self * 10_000).round().checked_to_num()
fn from_bps<Src: ToFixed>(bps: Src) -> Self {
let bps = Fraction::from_num(bps);
bps / 10_000
}

#[inline]
fn from_percent<Src: ToFixed>(percent: Src) -> Self {
let percent = Fraction::from_num(percent);
percent / 100
fn to_floor<Dst: FromFixed>(&self) -> Dst {
self.floor().to_num()
}

/*
#[inline]
fn from_bps<Src: ToFixed>(bps: Src) -> Self {
let bps = Fraction::from_num(bps);
bps / 10_000
fn to_percent<Dst: FromFixed>(&self) -> Option<Dst> {
(self * 100).round().checked_to_num()
}
#[inline]
fn from_percent<Src: ToFixed>(percent: Src) -> Self {
let percent = Fraction::from_num(percent);
percent / 100
}
#[inline]
Expand All @@ -89,11 +99,6 @@ impl FractionExtra for Fraction {
pow_fraction(*self, power)
}
#[inline]
fn to_floor<Dst: FromFixed>(&self) -> Dst {
self.floor().to_num()
}

#[inline]
fn to_ceil<Dst: FromFixed>(&self) -> Dst {
self.ceil().to_num()
Expand All @@ -118,6 +123,7 @@ impl FractionExtra for Fraction {
fn to_display(&self) -> FractionDisplay {
FractionDisplay(self)
}
*/
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, PartialOrd, Ord)]
Expand Down

0 comments on commit decad20

Please sign in to comment.