aboutsummaryrefslogtreecommitdiffstats
path: root/src/input.rs
diff options
context:
space:
mode:
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,
+ }
+ }
+}