aboutsummaryrefslogtreecommitdiffstats
path: root/src/unit_of_measurement.rs
diff options
context:
space:
mode:
authorsam-anthony <samanthony6@protonmail.com>2022-03-26 13:35:58 -0230
committersam-anthony <samanthony6@protonmail.com>2022-03-26 13:35:58 -0230
commite8c878f4236c056b1c0c9308e2d49c5b23833963 (patch)
tree01f53ee620e256fa7b87ea43656b9315735e9c2a /src/unit_of_measurement.rs
parent90f42ad66feb6b77474d0da267d572eca16e2826 (diff)
downloadvolute-e8c878f4236c056b1c0c9308e2d49c5b23833963.zip
pressure and rough layout
Diffstat (limited to 'src/unit_of_measurement.rs')
-rw-r--r--src/unit_of_measurement.rs54
1 files changed, 0 insertions, 54 deletions
diff --git a/src/unit_of_measurement.rs b/src/unit_of_measurement.rs
deleted file mode 100644
index ce459bf..0000000
--- a/src/unit_of_measurement.rs
+++ /dev/null
@@ -1,54 +0,0 @@
-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 {
- use super::UnitOfMeasurement;
-
- #[derive(Default, Clone)]
- pub struct Pressure(i32);
-
- #[derive(Copy, Clone)]
- pub enum Unit {
- Pascal = 1,
- KiloPascal = 1000,
- }
-
- impl Unit {
- // Pseudo iter::Cycle behavior.
- pub fn next(&mut self) {
- match self {
- Unit::Pascal => {
- *self = Unit::KiloPascal;
- }
- Unit::KiloPascal => {
- *self = Unit::Pascal;
- }
- }
- }
- }
-
- impl ToString for Unit {
- fn to_string(&self) -> String {
- match self {
- Self::Pascal => String::from("Pa"),
- Self::KiloPascal => String::from("kPa"),
- }
- }
- }
-
- impl UnitOfMeasurement for Pressure {
- type Unit = Unit;
-
- fn from_unit(unit: Self::Unit, n: i32) -> Self {
- Self(n * unit as i32)
- }
-
- fn as_unit(&self, unit: Self::Unit) -> i32 {
- self.0 / unit as i32
- }
- }
-}