X-Git-Url: http://git.scottworley.com/tablify/blobdiff_plain/116fc215a7f859e20b60e91bcb24d314a9d911f9..8bf0d5b1daaf4841b1c593630d3c862e72985dda:/src/lib.rs?ds=sidebyside diff --git a/src/lib.rs b/src/lib.rs index 199b8ab..7292f02 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -117,18 +117,13 @@ impl<'a, Input: Iterator>> Iterator for Re type Item = Result, std::io::Error>; fn next(&mut self) -> Option { 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)), - 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() } - 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!( @@ -136,12 +131,14 @@ impl<'a, Input: Iterator>> Iterator for Re 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 { - label: line, + // TODO: Don't leak + label: line.leak().trim_end(), entries: vec![], }); if prev.is_some() {