use core::cmp::Ord;
use num_traits::{cast::NumCast, Num};
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Encode, Decode, TypeInfo)]
pub struct Percent(u32);
impl Percent {
pub fn new(value: u32) -> Self {
Self(value)
}
pub fn value(self) -> u32 {
self.0
}
pub fn apply_to<T: Num + Ord + Copy + NumCast>(&self, value: T) -> T {
(value * NumCast::from(self.0).unwrap()) / NumCast::from(100).unwrap()
}
}
impl From<u32> for Percent {
fn from(value: u32) -> Self {
Self::new(value)
}
}
impl From<Percent> for gsys::Percent {
fn from(value: Percent) -> Self {
gsys::Percent::new(value.value())
}
}