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)),
- 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!(
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() {