diff options
Diffstat (limited to 'src/input.rs')
| -rw-r--r-- | src/input.rs | 85 |
1 files changed, 20 insertions, 65 deletions
diff --git a/src/input.rs b/src/input.rs index 6507986..00cf410 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1,62 +1,17 @@ +use crate::unit_of_measurement::{ + pressure::{Pressure, Unit::KiloPascal}, + UnitOfMeasurement, +}; + // A row in the inputs table has one of each variation. #[derive(Clone)] pub enum InputParam { - Rpm(String), // Revolutions per minute - Ve(String), // Volumetric efficiency - Map(String), // Manifold absolute pressure + Rpm(u32), // Revolutions per minute + Ve(u32), // Volumetric efficiency + Map(Pressure), // Manifold absolute pressure } impl InputParam { - /* Acts like the push() method of a Vec. - * Appends the given char to the end of the string contained by the - * InputParam. - */ - pub fn push(&mut self, c: char) { - match self { - Self::Rpm(rpm) => { - rpm.push(c); - *self = Self::Rpm(rpm.to_string()); - } - Self::Ve(ve) => { - ve.push(c); - *self = Self::Ve(ve.to_string()); - } - Self::Map(map) => { - map.push(c); - *self = Self::Map(map.to_string()); - } - } - } - - /* Acts like the pop() method of a Vec. - * Removes the last char from the string contained by the InputParam. - */ - pub fn pop(&mut self) { - match self { - Self::Rpm(rpm) => { - rpm.pop(); - *self = Self::Rpm(rpm.to_string()); - } - Self::Ve(ve) => { - ve.pop(); - *self = Self::Rpm(ve.to_string()); - } - Self::Map(map) => { - map.pop(); - *self = Self::Map(map.to_string()); - } - } - } - - // Return a copy of the string contained by the InputParam. - pub fn string(&self) -> String { - match self { - Self::Rpm(rpm) => rpm.to_string(), - Self::Ve(ve) => ve.to_string(), - Self::Map(map) => map.to_string(), - } - } - /* next() and previous() allow InputParam to act as a circular iterator of * sorts. next() will return the next variation as they are defined. When * it reaches the end, the first variation will be returned: @@ -66,17 +21,17 @@ impl InputParam { */ pub fn next(&self) -> Self { match self { - Self::Rpm(_) => Self::Ve(String::new()), - Self::Ve(_) => Self::Map(String::new()), - Self::Map(_) => Self::Rpm(String::new()), + Self::Rpm(_) => Self::Ve(0), + Self::Ve(_) => Self::Map(Pressure::default()), + Self::Map(_) => Self::Rpm(0), } } pub fn previous(&self) -> Self { match self { - Self::Rpm(_) => Self::Map(String::new()), - Self::Ve(_) => Self::Rpm(String::new()), - Self::Map(_) => Self::Ve(String::new()), + Self::Rpm(_) => Self::Map(Pressure::default()), + Self::Ve(_) => Self::Rpm(0), + Self::Map(_) => Self::Ve(0), } } } @@ -98,9 +53,9 @@ impl Row { impl Default for Row { fn default() -> Self { Self { - rpm: InputParam::Rpm(String::from("7000")), - ve: InputParam::Ve(String::from("95")), - map: InputParam::Map(String::from("200")), + rpm: InputParam::Rpm(7000), + ve: InputParam::Ve(95), + map: InputParam::Map(Pressure::from_unit(KiloPascal, 200)), } } } @@ -114,7 +69,7 @@ impl<'a> RowIter<'a> { fn from_row(row: &'a Row) -> Self { Self { row: row, - iter_state: Some(InputParam::Rpm(String::new())), + iter_state: Some(InputParam::Rpm(0)), } } } @@ -125,11 +80,11 @@ impl<'a> Iterator for RowIter<'a> { fn next(&mut self) -> Option<Self::Item> { match self.iter_state { Some(InputParam::Rpm(_)) => { - self.iter_state = Some(InputParam::Ve(String::new())); + self.iter_state = Some(InputParam::Ve(0)); Some(&self.row.rpm) } Some(InputParam::Ve(_)) => { - self.iter_state = Some(InputParam::Map(String::new())); + self.iter_state = Some(InputParam::Map(Pressure::default())); Some(&self.row.ve) } Some(InputParam::Map(_)) => { |