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
68
69
70
71
use crate::types::{temperatures::Kelvin, Quantity};
use std::cmp::Ordering;
use std::ops::Mul;
pub trait SpecificEnergy: Quantity {}
pub trait SpecificEnergyPerKelvin: Quantity {}
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "use_serde", derive(serde_derive::Serialize))]
#[cfg_attr(feature = "use_serde", derive(serde_derive::Deserialize))]
pub struct JpKg(pub f64);
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "use_serde", derive(serde_derive::Serialize))]
#[cfg_attr(feature = "use_serde", derive(serde_derive::Deserialize))]
pub struct JpKgpK(pub f64);
impl SpecificEnergy for JpKg {}
macro_rules! implQuantity {
($t:tt) => {
impl Quantity for $t {
#[inline]
fn pack(val: f64) -> Self {
$t(val)
}
#[inline]
fn unpack(self) -> f64 {
self.0
}
#[inline]
fn unwrap(self) -> f64 {
self.0
}
#[inline]
fn into_option(self) -> Option<f64> {
Some(self.0)
}
}
implOpsForQuantity!($t);
};
}
implQuantity!(JpKg);
implQuantity!(JpKgpK);
impl Mul<Kelvin> for JpKgpK {
type Output = JpKg;
fn mul(self, rhs: Kelvin) -> JpKg {
JpKg(self.0 * rhs.unpack())
}
}
impl Mul<JpKgpK> for Kelvin {
type Output = JpKg;
fn mul(self, rhs: JpKgpK) -> JpKg {
rhs * self
}
}