aboutsummaryrefslogtreecommitdiffstats
path: root/src/unit_of_measurement.rs
diff options
context:
space:
mode:
authorsam-anthony <samanthony6@protonmail.com>2022-03-06 21:56:57 -0330
committersam-anthony <samanthony6@protonmail.com>2022-03-06 21:56:57 -0330
commitd286ed3eb877365c01f7a7ec56de9a0dc84bab2e (patch)
tree8bf158027b0677bed2d1c06f13d42c426d30f263 /src/unit_of_measurement.rs
parentd0c7b0a39ed6703940da4896d2caa79ad36590e0 (diff)
downloadvolute-d286ed3eb877365c01f7a7ec56de9a0dc84bab2e.zip
simplify/remove a lot of stuff
Diffstat (limited to 'src/unit_of_measurement.rs')
-rw-r--r--src/unit_of_measurement.rs27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/unit_of_measurement.rs b/src/unit_of_measurement.rs
index 30a6ff3..a3b4b77 100644
--- a/src/unit_of_measurement.rs
+++ b/src/unit_of_measurement.rs
@@ -1,22 +1,33 @@
+pub trait UnitOfMeasurement {
+ type Unit;
+
+ fn from_unit(unit: Self::Unit, n: i32) -> Self;
+ fn as_unit(&self, unit: Self::Unit) -> i32;
+}
+
pub mod pressure {
- pub enum PressureUnit {
- Pascal = 1, // base unit. Every other variant will be a multiple of this.
- KiloPascal = 1000,
- }
+ use super::UnitOfMeasurement;
#[derive(Default)]
pub struct Pressure {
- val: i32, // Base unit is pascals.
+ val: i32,
}
- impl Pressure {
- pub fn from_unit(unit: PressureUnit, n: i32) -> Self {
+ pub enum Unit {
+ Pascal = 1,
+ KiloPascal = 1000,
+ }
+
+ impl UnitOfMeasurement for Pressure {
+ type Unit = Unit;
+
+ fn from_unit(unit: Self::Unit, n: i32) -> Self {
Self {
val: n * unit as i32,
}
}
- pub fn as_unit(&self, unit: PressureUnit) -> i32 {
+ fn as_unit(&self, unit: Self::Unit) -> i32 {
self.val / unit as i32
}
}