Skip to content

Commit

Permalink
Fix peeking_next
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen-CH-Leung committed May 17, 2024
1 parent 4bf4e4b commit 3920dbe
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/multipeek_general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ impl<I: Iterator, Idx: PeekIndex> MultiPeekGeneral<I, Idx> {
/// multiple times will not advance the internal state or the iterator, providing
/// a consistent view of the same element.
pub fn peek(&mut self) -> Option<&I::Item> {
// self.index.increment_index();
// self.peek_nth(0)
let ret = if self.index.index() < self.buf.len() {
Some(&self.buf[self.index.index()])
} else {
Expand Down Expand Up @@ -258,7 +256,17 @@ where
where
F: FnOnce(&Self::Item) -> bool,
{
self.peek_mut().filter(|item| accept(item))?;
if self.buf.is_empty() {
if let Some(r) = self.peek() {
if !accept(r) {
return None;

Check warning on line 262 in src/multipeek_general.rs

View check run for this annotation

Codecov / codecov/patch

src/multipeek_general.rs#L262

Added line #L262 was not covered by tests
}
}

Check warning on line 264 in src/multipeek_general.rs

View check run for this annotation

Codecov / codecov/patch

src/multipeek_general.rs#L264

Added line #L264 was not covered by tests
} else if let Some(r) = self.buf.front() {
if !accept(r) {
return None;
}
}

Check warning on line 269 in src/multipeek_general.rs

View check run for this annotation

Codecov / codecov/patch

src/multipeek_general.rs#L269

Added line #L269 was not covered by tests
self.next()
}
}

0 comments on commit 3920dbe

Please sign in to comment.