metfor/types/
unitless.rs

1use crate::types::Quantity;
2
3impl Quantity for f64 {
4    fn pack(val: f64) -> f64 {
5        val
6    }
7
8    fn unpack(self) -> f64 {
9        self
10    }
11
12    fn unwrap(self) -> f64 {
13        self
14    }
15
16    fn into_option(self) -> Option<f64> {
17        Some(self)
18    }
19}
20
21// Added u8 so I could treat some simple integer indexes as quantities too.
22impl Quantity for u8 {
23    fn pack(val: f64) -> u8 {
24        val as u8
25    }
26
27    fn unpack(self) -> f64 {
28        f64::from(self)
29    }
30
31    fn unwrap(self) -> f64 {
32        f64::from(self)
33    }
34
35    fn into_option(self) -> Option<f64> {
36        Some(f64::from(self))
37    }
38}
39
40// No need to use implOpsForQuantity macro here, all those ops should already be defined for
41// f64 and u8!