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
use std::ops::Mul;

#[derive(Debug, PartialEq, Clone, Copy)]
pub enum Score {
    Real(f64),
    Fake(f64),
}


impl Score {
    pub fn value(&self) -> f64 {
        match *self {
            Score::Real(v) | Score::Fake(v) => v,
        }
    }

    pub fn value_ref_mut(&mut self) -> &mut f64 {
        match *self {
            Score::Real(ref mut v) | Score::Fake(ref mut v) => v,
        }
    }
}


impl Mul for Score {
    type Output = Self;
    fn mul(self, rhs: Self) -> Self::Output {
        match (self, rhs) {
            (Score::Real(a), Score::Real(b)) => Score::Real(a * b),
            _ => Score::Fake(self.value() * rhs.value()),
        }
    }
}


impl Mul<f64> for Score {
    type Output = Self;
    fn mul(self, rhs: f64) -> Self::Output {
        match self {
            Score::Real(v) => Score::Real(v * rhs),
            Score::Fake(v) => Score::Fake(v * rhs),
        }
    }
}