diff --git a/src/rio/ntriples/mod.rs b/src/rio/ntriples/mod.rs index 887e9d00..3dc0306e 100644 --- a/src/rio/ntriples/mod.rs +++ b/src/rio/ntriples/mod.rs @@ -25,18 +25,17 @@ impl Iterator for NTriplesIterator { type Item = Result; fn next(&mut self) -> Option> { - match self.reader.read_line(&mut self.buffer) { - Ok(line_count) => if line_count == 0 { - None - } else { - let result = grammar::triple(&self.buffer, &mut self.bnodes_map); - self.buffer.clear(); - match result { - Ok(Some(triple)) => Some(Ok(triple)), - Ok(None) => self.next(), - Err(error) => Some(Err(error.into())), - } - }, + if let Err(error) = self.reader.read_line(&mut self.buffer) { + return Some(Err(error.into())); + } + if self.buffer.is_empty() { + return None; //End of file + } + let result = grammar::triple(&self.buffer, &mut self.bnodes_map); + self.buffer.clear(); + match result { + Ok(Some(triple)) => Some(Ok(triple)), + Ok(None) => self.next(), Err(error) => Some(Err(error.into())), } }