af_utilities/types/
balance9.rs

1use std::ops::Mul;
2
3use num_traits::One;
4use serde::Serialize;
5
6#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
7pub struct Balance9(u64);
8
9impl Mul for Balance9 {
10    type Output = Self;
11
12    fn mul(self, rhs: Self) -> Self::Output {
13        let (Self(lhs), Self(rhs)) = (self, rhs);
14        Self(lhs * rhs / Self::one().into_inner())
15    }
16}
17
18impl From<f64> for Balance9 {
19    fn from(value: f64) -> Self {
20        let Self(one) = Self::one();
21        let one_f64 = one as f64;
22        Self((one_f64 * value) as u64)
23    }
24}
25
26impl One for Balance9 {
27    fn one() -> Self {
28        Self(1_000_000_000)
29    }
30}
31
32impl Balance9 {
33    pub const fn into_inner(self) -> u64 {
34        self.0
35    }
36
37    pub const fn from_inner(int: u64) -> Self {
38        Self(int)
39    }
40}