Refactor names and imports
This commit is contained in:
@@ -44,7 +44,13 @@ pub use phonenumberutil::{
|
||||
errors::{*},
|
||||
enums::{*},
|
||||
};
|
||||
pub use generated::proto::phonemetadata::{*};
|
||||
pub use generated::proto::phonemetadata;
|
||||
pub use generated::proto::phonenumber::PhoneNumber;
|
||||
pub use generated::proto::phonenumber::phone_number::CountryCodeSource;
|
||||
pub use regexp_cache::InvalidRegexError;
|
||||
mod tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
}
|
||||
@@ -17,12 +17,12 @@ use std::num::ParseIntError;
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::regexp_cache::ErrorInvalidRegex;
|
||||
use crate::regexp_cache::InvalidRegexError;
|
||||
|
||||
#[derive(Debug, PartialEq, Error)]
|
||||
pub enum InternalLogicError {
|
||||
#[error("{0}")]
|
||||
InvalidRegex(#[from] ErrorInvalidRegex),
|
||||
InvalidRegex(#[from] InvalidRegexError),
|
||||
|
||||
#[error("{0}")]
|
||||
InvalidMetadataForValidRegion(#[from] InvalidMetadataForValidRegionError)
|
||||
@@ -43,7 +43,7 @@ pub enum ParseError {
|
||||
#[error("Too long nsn")]
|
||||
TooLongNsn, // TOO_LONG in the java version.
|
||||
#[error("{0}")]
|
||||
InvalidRegex(#[from] ErrorInvalidRegex),
|
||||
InvalidRegex(#[from] InvalidRegexError),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Error)]
|
||||
|
||||
@@ -45,7 +45,7 @@ use crate::{
|
||||
phonenumber::{phone_number::CountryCodeSource, PhoneNumber}
|
||||
},
|
||||
region_code::RegionCode, interfaces::MatcherApi, macros::owned_from_cow_or,
|
||||
regex_based_matcher::RegexBasedMatcher, regex_util::{RegexConsume, RegexFullMatch}, regexp_cache::ErrorInvalidRegex, string_util::strip_cow_prefix
|
||||
regex_based_matcher::RegexBasedMatcher, regex_util::{RegexConsume, RegexFullMatch}, regexp_cache::InvalidRegexError, string_util::strip_cow_prefix
|
||||
};
|
||||
|
||||
use dec_from_char::DecimalExtended;
|
||||
@@ -54,7 +54,7 @@ use regex::Regex;
|
||||
|
||||
// Helper type for Result
|
||||
|
||||
pub type RegexResult<T> = std::result::Result<T, ErrorInvalidRegex>;
|
||||
pub type RegexResult<T> = std::result::Result<T, InvalidRegexError>;
|
||||
|
||||
pub type ParseResult<T> = std::result::Result<T, ParseError>;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
use log::{error};
|
||||
use super::regex_util::{RegexFullMatch, RegexConsume};
|
||||
|
||||
use crate::{interfaces, generated::proto::phonemetadata::PhoneNumberDesc, regexp_cache::{ErrorInvalidRegex, RegexCache}};
|
||||
use crate::{interfaces, generated::proto::phonemetadata::PhoneNumberDesc, regexp_cache::{InvalidRegexError, RegexCache}};
|
||||
|
||||
pub struct RegexBasedMatcher {
|
||||
cache: RegexCache,
|
||||
@@ -32,7 +32,7 @@ impl RegexBasedMatcher {
|
||||
&self, phone_number: &str,
|
||||
number_pattern: &str,
|
||||
allow_prefix_match: bool
|
||||
) -> Result<bool, ErrorInvalidRegex> {
|
||||
) -> Result<bool, InvalidRegexError> {
|
||||
let regexp = self.cache.get_regex(number_pattern)?;
|
||||
|
||||
// find first occurrence
|
||||
|
||||
@@ -20,7 +20,7 @@ use thiserror::Error;
|
||||
|
||||
#[derive(Debug, PartialEq, Error)]
|
||||
#[error("An error occurred while trying to create regex: {0}")]
|
||||
pub struct ErrorInvalidRegex(#[from] regex::Error);
|
||||
pub struct InvalidRegexError(#[from] regex::Error);
|
||||
|
||||
pub struct RegexCache {
|
||||
cache: DashMap<String, Arc<regex::Regex>>
|
||||
@@ -34,7 +34,7 @@ impl RegexCache {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_regex(&self, pattern: &str) -> Result<Arc<regex::Regex>, ErrorInvalidRegex> {
|
||||
pub fn get_regex(&self, pattern: &str) -> Result<Arc<regex::Regex>, InvalidRegexError> {
|
||||
if let Some(regex) = self.cache.get(pattern) {
|
||||
Ok(regex.value().clone())
|
||||
} else {
|
||||
|
||||
@@ -1,11 +1,22 @@
|
||||
use protobuf::{Message, MessageField};
|
||||
|
||||
use crate::{
|
||||
phonenumberutil::{
|
||||
enums::{
|
||||
PhoneNumberFormat, PhoneNumberType, NumberLengthType,
|
||||
ParseError, ValidationError,
|
||||
NumberFormat, PhoneMetadata, PhoneMetadataCollection, PhoneNumberDesc,
|
||||
CountryCodeSource, PhoneNumber,
|
||||
PhoneNumberUtil,
|
||||
},
|
||||
errors::{
|
||||
ParseError, ValidationError
|
||||
}
|
||||
},
|
||||
generated::proto::{
|
||||
phonemetadata::{
|
||||
NumberFormat, PhoneMetadata, PhoneMetadataCollection, PhoneNumberDesc
|
||||
},
|
||||
phonenumber::phone_number::CountryCodeSource,
|
||||
phonenumber::PhoneNumber,
|
||||
},
|
||||
phonenumberutil::phonenumberutil::PhoneNumberUtil,
|
||||
};
|
||||
|
||||
use super::region_code::RegionCode;
|
||||
|
||||
Reference in New Issue
Block a user