From e72187d2d71b068b9e6d8c0e0f414d5c711e2bfd Mon Sep 17 00:00:00 2001 From: Vlasislav Kashin <99754299+vloldik@users.noreply.github.com> Date: Thu, 10 Jul 2025 12:50:12 +0300 Subject: [PATCH] Better None handling: Remove unwrap --- src/phonenumberutil/phonenumberutil.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/phonenumberutil/phonenumberutil.rs b/src/phonenumberutil/phonenumberutil.rs index dca3746..d857b28 100644 --- a/src/phonenumberutil/phonenumberutil.rs +++ b/src/phonenumberutil/phonenumberutil.rs @@ -2319,12 +2319,15 @@ impl PhoneNumberUtil { let first_capture = captures.as_ref().and_then(| c | c.get(1)); let second_capture = captures.as_ref().and_then(| c | c.get(2)); - if !transform_rule.is_empty() && - (second_capture.is_some_and(| c | !c.is_empty() && first_capture.is_some()) - || first_capture.is_some_and(| c | !c.is_empty() && second_capture.is_none())) { + let condition = |first_capture: ®ex::Match<'_>| { + !transform_rule.is_empty() && + (second_capture.is_some_and(| c | !c.is_empty()) || + !first_capture.is_empty() && second_capture.is_none()) + }; + + if let Some(first_capture) = first_capture.filter(condition) { // here we can safe unwrap because first_capture.is_some() anyway - let first_capture = first_capture.unwrap(); let carrier_code_temp = if second_capture.is_some() { Some(first_capture.as_str()) } else {