aboutsummaryrefslogtreecommitdiffstats
path: root/src/input.rs
diff options
context:
space:
mode:
authorsam-anthony <samanthony6@protonmail.com>2022-02-05 21:42:28 -0330
committersam-anthony <samanthony6@protonmail.com>2022-02-05 21:42:28 -0330
commitffffee2ac77c88ea0219b1b0e39e3988ed918319 (patch)
treef980f16f7ecc3176e36f7ea152122f11e1209486 /src/input.rs
parentfd512094eb013e512c1faa98eb168bbc0b23859b (diff)
downloadvolute-ffffee2ac77c88ea0219b1b0e39e3988ed918319.zip
impl Iterator for Row for building input table
Diffstat (limited to 'src/input.rs')
-rw-r--r--src/input.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/input.rs b/src/input.rs
index 513aef6..8f80a1d 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -95,6 +95,12 @@ pub struct Row {
pub map: InputParam,
}
+impl Row {
+ pub fn iter(&self) -> RowIter {
+ RowIter::from_row(&self)
+ }
+}
+
impl Default for Row {
fn default() -> Self {
Self {
@@ -104,3 +110,39 @@ impl Default for Row {
}
}
}
+
+pub struct RowIter<'a> {
+ row: &'a Row,
+ iter_state: Option<InputParam>,
+}
+
+impl<'a> RowIter<'a> {
+ fn from_row(row: &'a Row) -> Self {
+ Self {
+ row: row,
+ iter_state: Some(InputParam::Rpm(String::new())),
+ }
+ }
+}
+
+impl<'a> Iterator for RowIter<'a> {
+ type Item = &'a InputParam;
+
+ fn next(&mut self) -> Option<Self::Item> {
+ match self.iter_state {
+ Some(InputParam::Rpm(_)) => {
+ self.iter_state = Some(InputParam::Ve(String::new()));
+ Some(&self.row.rpm)
+ }
+ Some(InputParam::Ve(_)) => {
+ self.iter_state = Some(InputParam::Map(String::new()));
+ Some(&self.row.ve)
+ }
+ Some(InputParam::Map(_)) => {
+ self.iter_state = None;
+ Some(&self.row.map)
+ }
+ None => None,
+ }
+ }
+}