Skip to content

Commit

Permalink
adopt peak to return next optional item
Browse files Browse the repository at this point in the history
  • Loading branch information
titaneric committed Jan 11, 2025
1 parent 516c4f8 commit ea723d6
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/format/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,17 +317,10 @@ where
}};
}

// convert items to a pair (current, Option(next_item))
// so we can have information about the next item
let items: Vec<B> = items.collect::<Vec<_>>();
let last_item = items.last();
let mut items: Vec<(&B, Option<&B>)> =
items.windows(2).map(|arr| (&arr[0], Some(&arr[1]))).collect::<Vec<_>>();
if let Some(last_item) = last_item {
items.push((last_item, None));
}
let mut items_iter = items.peekable();

for (item, next_item) in items {
while let Some(item) = items_iter.next() {
let next_item = items_iter.peek();
match *item.borrow() {
Item::Literal(prefix) => {
if s.len() < prefix.len() {
Expand Down

0 comments on commit ea723d6

Please sign in to comment.