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
66
67
pub struct Score {
    pub value: f32,
}

impl Score {
    pub fn from_float(value: f32) -> Self {
        Score { value }
    }

    pub fn from_int(value: i32) -> Self {
        Score {
            value: value as f32,
        }
    }

    pub fn from_usize(value: usize) -> Self {
        Score {
            value: value as f32,
        }
    }

    pub fn from_string(value: &str) -> Self {
        Score {
            value: value.parse::<f32>().unwrap(),
        }
    }

    pub fn as_float(&self) -> f32 {
        self.value
    }

    pub fn as_int(&self) -> i32 {
        self.value as i32
    }

    pub fn as_string(&self) -> String {
        self.value.to_string()
    }

    pub fn as_usize(&self) -> usize {
        self.value as usize
    }
}

impl Clone for Score {
    fn clone(&self) -> Self {
        Score { value: self.value }
    }
}

impl PartialEq for Score {
    fn eq(&self, other: &Self) -> bool {
        self.value == other.value
    }
}

impl PartialOrd for Score {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        self.value.partial_cmp(&other.value)
    }
}

impl std::fmt::Debug for Score {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.value)
    }
}