diff --git a/src/reader/buffered_reader.rs b/src/reader/buffered_reader.rs index 8585c7c4..e40a1e98 100644 --- a/src/reader/buffered_reader.rs +++ b/src/reader/buffered_reader.rs @@ -202,13 +202,12 @@ macro_rules! impl_buffered_source { } } - $($async)? fn skip_one(&mut self, byte: u8, position: &mut usize) -> Result { + $($async)? fn skip_one(&mut self, byte: u8) -> Result { // search byte must be within the ascii range debug_assert!(byte.is_ascii()); match self.peek_one() $(.$await)? ? { Some(b) if b == byte => { - *position += 1; self $(.$reader)? .consume(1); Ok(true) } @@ -219,8 +218,7 @@ macro_rules! impl_buffered_source { $($async)? fn peek_one(&mut self) -> Result> { loop { break match self $(.$reader)? .fill_buf() $(.$await)? { - Ok(n) if n.is_empty() => Ok(None), - Ok(n) => Ok(Some(n[0])), + Ok(n) => Ok(n.first().cloned()), Err(ref e) if e.kind() == io::ErrorKind::Interrupted => continue, Err(e) => Err(Error::Io(e.into())), }; diff --git a/src/reader/mod.rs b/src/reader/mod.rs index 0301c8c2..ff885d50 100644 --- a/src/reader/mod.rs +++ b/src/reader/mod.rs @@ -279,7 +279,8 @@ macro_rules! read_until_open { } // If we already at the `<` symbol, do not try to return an empty Text event - if $reader.skip_one(b'<', &mut $self.state.offset) $(.$await)? ? { + if $reader.skip_one(b'<') $(.$await)? ? { + $self.state.offset += 1; $self.state.state = ParseState::OpenedTag; // Pass $buf to the next next iteration of parsing loop return Ok(Err($buf)); @@ -889,8 +890,8 @@ trait XmlSource<'r, B> { /// `true` if it matched. /// /// # Parameters - /// - `position`: Will be increased by 1 if byte is matched - fn skip_one(&mut self, byte: u8, position: &mut usize) -> Result; + /// - `byte`: Character to skip + fn skip_one(&mut self, byte: u8) -> Result; /// Return one character without consuming it, so that future `read_*` calls /// will still include it. On EOF, return `None`. diff --git a/src/reader/slice_reader.rs b/src/reader/slice_reader.rs index 8ad7e702..6dd5546c 100644 --- a/src/reader/slice_reader.rs +++ b/src/reader/slice_reader.rs @@ -322,12 +322,11 @@ impl<'a> XmlSource<'a, ()> for &'a [u8] { Ok(()) } - fn skip_one(&mut self, byte: u8, position: &mut usize) -> Result { + fn skip_one(&mut self, byte: u8) -> Result { // search byte must be within the ascii range debug_assert!(byte.is_ascii()); if self.first() == Some(&byte) { *self = &self[1..]; - *position += 1; Ok(true) } else { Ok(false)