]> git.scottworley.com Git - tablify/blobdiff - src/lib.rs
Move the trim_end() down
[tablify] / src / lib.rs
index 199b8abd2732705484cc770b5ee948af71da332c..7292f0237d6765abed9e3d1b8d30143744aa3263 100644 (file)
@@ -117,18 +117,13 @@ impl<'a, Input: Iterator<Item = Result<String, std::io::Error>>> Iterator for Re
     type Item = Result<RowInput<'a>, std::io::Error>;
     fn next(&mut self) -> Option<Self::Item> {
         loop {
     type Item = Result<RowInput<'a>, std::io::Error>;
     fn next(&mut self) -> Option<Self::Item> {
         loop {
-            match self
-                .input
-                .next()
-                // TODO: Don't leak
-                .map(|(n, r)| (n, r.map(|line| String::from(line).leak().trim_end())))
-            {
+            match self.input.next() {
                 None => return Ok(std::mem::take(&mut self.row)).transpose(),
                 Some((_, Err(e))) => return Some(Err(e)),
                 None => return Ok(std::mem::take(&mut self.row)).transpose(),
                 Some((_, Err(e))) => return Some(Err(e)),
-                Some((_, Ok(line))) if line.is_empty() && self.row.is_some() => {
+                Some((_, Ok(line))) if line.trim_end().is_empty() && self.row.is_some() => {
                     return Ok(std::mem::take(&mut self.row)).transpose()
                 }
                     return Ok(std::mem::take(&mut self.row)).transpose()
                 }
-                Some((_, Ok(line))) if line.is_empty() => {}
+                Some((_, Ok(line))) if line.trim_end().is_empty() => {}
                 Some((n, Ok(line))) if line.starts_with(' ') => match &mut self.row {
                     None => {
                         return Some(Err(std::io::Error::other(format!(
                 Some((n, Ok(line))) if line.starts_with(' ') => match &mut self.row {
                     None => {
                         return Some(Err(std::io::Error::other(format!(
@@ -136,12 +131,14 @@ impl<'a, Input: Iterator<Item = Result<String, std::io::Error>>> Iterator for Re
                             n + 1
                         ))))
                     }
                             n + 1
                         ))))
                     }
-                    Some(ref mut row) => row.entries.push(Entry::from(line.trim())),
+                    // TODO: Don't leak
+                    Some(ref mut row) => row.entries.push(Entry::from(line.leak().trim())),
                 },
                 Some((_, Ok(line))) => {
                     let prev = std::mem::take(&mut self.row);
                     self.row = Some(RowInput {
                 },
                 Some((_, Ok(line))) => {
                     let prev = std::mem::take(&mut self.row);
                     self.row = Some(RowInput {
-                        label: line,
+                        // TODO: Don't leak
+                        label: line.leak().trim_end(),
                         entries: vec![],
                     });
                     if prev.is_some() {
                         entries: vec![],
                     });
                     if prev.is_some() {