aboutsummaryrefslogtreecommitdiffstats
path: root/src/volume/cubic_metre.rs
blob: a908b11212f4a036816efed61a2db89e3ccc8064 (plain) (blame)
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
use super::{CubicCentimetre, Litre, Unit};

#[derive(Debug, Default, PartialEq)]
pub struct CubicMetre(pub f64);

impl CubicMetre {
    pub fn from_unit<F: Into<f64>>(unit: Unit, value: F) -> Self {
        match unit {
            Unit::CubicMetre => Self(value.into()),
            Unit::Litre => Self::from(Litre(value.into())),
            Unit::CubicCentimetre => Self::from(CubicCentimetre(value.into())),
        }
    }
}

impl From<Litre> for CubicMetre {
    fn from(value: Litre) -> Self {
        Self(value.0 * 10_f64.powi(-3))
    }
}

impl From<CubicCentimetre> for CubicMetre {
    fn from(value: CubicCentimetre) -> Self {
        Self(value.0 * 10_f64.powi(-6))
    }
}