aboutsummaryrefslogtreecommitdiffstats
path: root/src/volume/cubic_metre.rs
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2023-01-20 20:04:28 -0330
committerSam Anthony <sam@samanthony.xyz>2023-01-20 20:04:28 -0330
commit3a1e9d081cc299a0ce3e950282464986a36376d9 (patch)
tree1f01505157643ad9b42fd0fc3006126d6e524838 /src/volume/cubic_metre.rs
parent413608ea229f0adec21feb27501178ccadd47844 (diff)
downloadvolute-3a1e9d081cc299a0ce3e950282464986a36376d9.zip
refactor volume module
Diffstat (limited to 'src/volume/cubic_metre.rs')
-rw-r--r--src/volume/cubic_metre.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/volume/cubic_metre.rs b/src/volume/cubic_metre.rs
new file mode 100644
index 0000000..a908b11
--- /dev/null
+++ b/src/volume/cubic_metre.rs
@@ -0,0 +1,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))
+ }
+}