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
65
use crate::{Currency, CurrencyLocale};
use std::ops::Mul;

impl<L: CurrencyLocale + Default> Mul<usize> for Currency<L> {
    type Output = Self;

    fn mul(self, rhs: usize) -> Self::Output {
        let rhs = rhs as f32;
        let tmp = (self.full as f32 + self.part as f32 / 100.0) * rhs;
        let mut result: Currency<L> = tmp.into();
        result.locale = self.locale;

        result
    }
}

impl<L: CurrencyLocale + Default> Mul<Currency<L>> for usize {
    type Output = Currency<L>;

    fn mul(self, rhs: Currency<L>) -> Self::Output {
        rhs * self
    }
}

impl<L: CurrencyLocale + Default> Mul<f32> for Currency<L> {
    type Output = Self;

    fn mul(self, rhs: f32) -> Self::Output {
        let tmp = (self.full as f32 + self.part as f32 / 100.0) * rhs;

        let mut result = Self::from(tmp);
        result.negative = self.negative ^ rhs.is_sign_negative();
        result.locale = self.locale;
        result
    }
}

impl<L: CurrencyLocale + Default> Mul<Currency<L>> for f32 {
    type Output = Currency<L>;

    fn mul(self, rhs: Currency<L>) -> Self::Output {
        rhs * self
    }
}

impl<L: CurrencyLocale + Default> Mul<f64> for Currency<L> {
    type Output = Self;

    fn mul(self, rhs: f64) -> Self::Output {
        let tmp = (self.full as f64 + self.part as f64 / 100.0) * rhs;

        let mut result = Self::from(tmp);
        result.negative = self.negative ^ rhs.is_sign_negative();
        result.locale = self.locale;
        result
    }
}

impl<L: CurrencyLocale + Default> Mul<Currency<L>> for f64 {
    type Output = Currency<L>;

    fn mul(self, rhs: Currency<L>) -> Self::Output {
        rhs * self
    }
}