From e52a19e6c19642bd4bd2bd5f41f789fd57d726cb Mon Sep 17 00:00:00 2001 From: Vlasislav Kashin <99754299+vloldik@users.noreply.github.com> Date: Thu, 10 Jul 2025 13:00:41 +0300 Subject: [PATCH] Remove unused, refactor exports --- src/lib.rs | 18 +++++++++++++++++- src/phonenumberutil/enums.rs | 1 - src/phonenumberutil/errors.rs | 1 - src/phonenumberutil/mod.rs | 18 ++++++++---------- src/phonenumberutil/phonenumberutil.rs | 8 ++++---- src/regex_util.rs | 15 --------------- src/regexp_cache.rs | 7 +------ 7 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ed34064..2a0b04d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,4 +13,20 @@ pub(crate) mod string_util; /// boilerplate places in the code that can be replaced with macros, /// the name of which will describe what is happening more /// clearly than a few lines of code. -mod macros; \ No newline at end of file +mod macros; + +pub use phonenumberutil::{ + PHONE_NUMBER_UTIL, + phonenumberutil::{ + RegexResult, + MatchResult, + ParseResult, + ValidationResult, + ExampleNumberResult, + InternalLogicResult, + ExtractNumberResult, + PhoneNumberUtil + }, + errors, + enums +}; \ No newline at end of file diff --git a/src/phonenumberutil/enums.rs b/src/phonenumberutil/enums.rs index 8f45f5c..ebccc9c 100644 --- a/src/phonenumberutil/enums.rs +++ b/src/phonenumberutil/enums.rs @@ -1,5 +1,4 @@ use strum::EnumIter; -use thiserror::Error; /// INTERNATIONAL and NATIONAL formats are consistent with the definition /// in ITU-T Recommendation E.123. However we follow local conventions such as diff --git a/src/phonenumberutil/errors.rs b/src/phonenumberutil/errors.rs index 59aa3c9..3156117 100644 --- a/src/phonenumberutil/errors.rs +++ b/src/phonenumberutil/errors.rs @@ -1,4 +1,3 @@ -use core::error; use std::num::ParseIntError; use thiserror::Error; diff --git a/src/phonenumberutil/mod.rs b/src/phonenumberutil/mod.rs index 195513a..21d2abb 100644 --- a/src/phonenumberutil/mod.rs +++ b/src/phonenumberutil/mod.rs @@ -1,8 +1,8 @@ mod helper_constants; -pub mod helper_functions; -mod errors; -mod enums; -mod phonenumberutil; +mod helper_functions; +pub mod errors; +pub mod enums; +pub mod phonenumberutil; mod phone_number_regexps_and_mappings; pub(self) mod helper_types; pub(self) mod comparisons; @@ -10,10 +10,8 @@ pub(self) mod comparisons; use std::sync::LazyLock; pub use enums::{MatchType, PhoneNumberFormat, PhoneNumberType, ValidNumberLenType}; -use thiserror::Error; +use crate::phonenumberutil::phonenumberutil::PhoneNumberUtil; -// use crate::phonenumberutil::phonenumberutil::PhoneNumberUtil; - -// static PHONE_NUMBER_UTIL: LazyLock = LazyLock::new(|| { -// PhoneNumberUtil::new() -// }); \ No newline at end of file +pub static PHONE_NUMBER_UTIL: LazyLock = LazyLock::new(|| { + PhoneNumberUtil::new() +}); \ No newline at end of file diff --git a/src/phonenumberutil/phonenumberutil.rs b/src/phonenumberutil/phonenumberutil.rs index d857b28..e6e11d7 100644 --- a/src/phonenumberutil/phonenumberutil.rs +++ b/src/phonenumberutil/phonenumberutil.rs @@ -1,5 +1,5 @@ use std::{ - borrow::Cow, cmp::max, collections::{hash_map, HashMap, HashSet, VecDeque}, sync::Arc + borrow::Cow, cmp::max, collections::{HashMap, HashSet, VecDeque}, sync::Arc }; use super::phone_number_regexps_and_mappings::PhoneNumberRegExpsAndMappings; @@ -136,13 +136,13 @@ impl PhoneNumberUtil { self.country_code_to_non_geographical_metadata_map.keys().map(| k | *k) } - fn get_supported_calling_codes(&self) -> impl Iterator { + pub fn get_supported_calling_codes(&self) -> impl Iterator { self.country_calling_code_to_region_code_map .iter() .map(| (k, _) | *k) } - fn get_supported_types_for_region( + pub fn get_supported_types_for_region( &self, region_code: &str, ) -> Option> { @@ -155,7 +155,7 @@ impl PhoneNumberUtil { }) } - fn get_supported_types_for_non_geo_entity( + pub fn get_supported_types_for_non_geo_entity( &self, country_calling_code: i32, ) -> Option> { diff --git a/src/regex_util.rs b/src/regex_util.rs index ea440f2..0d6e9d8 100644 --- a/src/regex_util.rs +++ b/src/regex_util.rs @@ -14,11 +14,6 @@ pub trait RegexConsume { fn find_start<'a>(&self, s: &'a str) -> Option>; } -trait RegexMatchStart { - // Eq of looking_at - fn match_start(&self, s: &str) -> bool; -} - impl RegexFullMatch for Regex { fn full_match(&self, s: &str) -> bool { let found = self.find(s); @@ -29,16 +24,6 @@ impl RegexFullMatch for Regex { } } -impl RegexMatchStart for Regex { - fn match_start(&self, s: &str) -> bool { - let found = self.find(s); - if let Some(matched) = found { - return matched.start() == 0; - } - false - } -} - impl RegexConsume for Regex { fn captures_start<'a>(&self, s: &'a str) -> Option> { let captures = self.captures(s)?; diff --git a/src/regexp_cache.rs b/src/regexp_cache.rs index 5ffea35..8828b45 100644 --- a/src/regexp_cache.rs +++ b/src/regexp_cache.rs @@ -12,12 +12,7 @@ pub struct RegexCache { } impl RegexCache { - pub fn new() -> Self { - Self { - cache: DashMap::new(), - } - } - + pub fn with_capacity(capacity: usize) -> Self { Self { cache: DashMap::with_capacity(capacity),