From ea723d6548ac8944a21f6f038eb5c0fd511e8507 Mon Sep 17 00:00:00 2001 From: "chenyee.cy.huang" Date: Sat, 11 Jan 2025 18:38:49 +0800 Subject: [PATCH] adopt peak to return next optional item --- src/format/parse.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/format/parse.rs b/src/format/parse.rs index 6fac97b6f..be088fa75 100644 --- a/src/format/parse.rs +++ b/src/format/parse.rs @@ -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 = items.collect::>(); - let last_item = items.last(); - let mut items: Vec<(&B, Option<&B>)> = - items.windows(2).map(|arr| (&arr[0], Some(&arr[1]))).collect::>(); - 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() {