As a side effect, this also removes trailing whitespace, which nice.
type Item = Result<RowInput, std::io::Error>;
fn next(&mut self) -> Option<Self::Item> {
loop {
type Item = Result<RowInput, std::io::Error>;
fn next(&mut self) -> Option<Self::Item> {
loop {
- match self.input.next() {
+ match self
+ .input
+ .next()
+ .map(|r| r.map(|line| String::from(line.trim_end())))
+ {
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() => {
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() => {
+ assert_eq!(
+ read_rows(&b"foo\n \nbar\n"[..])
+ .flatten()
+ .collect::<Vec<_>>(),
+ vec![
+ RowInput {
+ label: String::from("foo"),
+ entries: vec![]
+ },
+ RowInput {
+ label: String::from("bar"),
+ entries: vec![]
+ }
+ ]
+ );
+ assert_eq!(
+ read_rows(&b"foo \n bar \n"[..])
+ .flatten()
+ .collect::<Vec<_>>(),
+ vec![RowInput {
+ label: String::from("foo"),
+ entries: vec![String::from("bar")]
+ }]
+ );
let bad = read_rows(&b" foo"[..]).next().unwrap();
assert!(bad.is_err());
let bad = read_rows(&b" foo"[..]).next().unwrap();
assert!(bad.is_err());