From fe17f4adbb97195fa9336785c5e186b5aed03b0f Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Sun, 21 Jul 2024 14:54:39 -0700 Subject: [PATCH] typegen: make reference sep parser more idiomatic --- typegen/src/parse.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/typegen/src/parse.rs b/typegen/src/parse.rs index 515c9dd..24966fb 100644 --- a/typegen/src/parse.rs +++ b/typegen/src/parse.rs @@ -656,17 +656,13 @@ fn parse_details(comment: Comment) -> String { (':', false), ]; - let mut chars = src.chars().enumerate(); - let (end, ty) = loop { - match chars.next() { - Some((i, c)) => { - if let Some(strip) = separators.iter().filter(|(sc, _)| c == *sc).map(|(_, strip)| *strip).next() { - break (i + if strip { 1 } else { 0 }, &src[..i]); - } - }, - None => break (src.len(), src), - } - }; + let (end, ty) = src.chars().enumerate() + .find_map(|(i, char)| { + separators.iter() + .find(|(sc, _)| char == *sc) + .map(|(_, strip)| (i + if *strip { 1 } else { 0 }, &src[..i])) + }) + .unwrap_or_else(|| (src.len(), src)); let mut split = ty.rsplit_once('.').unwrap_or(("", ty));