pub struct PhoneNumber {
pub original: String,
pub normalized: String,
pub country: Option<&'static Country>,
pub phone_type: Option<PhoneNumberType>,
}Expand description
A parsed and validated phone number with equality comparison
Two PhoneNumber instances are considered equal if they represent
the same phone number, regardless of their original formatting.
§Examples
use phonelib::PhoneNumber;
let num1 = PhoneNumber::parse("+12025550173").unwrap();
let num2 = PhoneNumber::parse("12025550173").unwrap();
assert_eq!(num1, num2); // Same number, different formatsFields§
§original: StringThe original input string
normalized: StringThe normalized E.164 format
country: Option<&'static Country>The country information
phone_type: Option<PhoneNumberType>The phone number type
Implementations§
Source§impl PhoneNumber
impl PhoneNumber
Sourcepub fn parse_with_country(input: &str, country_code: &str) -> Option<Self>
pub fn parse_with_country(input: &str, country_code: &str) -> Option<Self>
Sourcepub fn national_number(&self) -> String
pub fn national_number(&self) -> String
Get the national number (without country code)
Sourcepub fn country_code(&self) -> Option<u32>
pub fn country_code(&self) -> Option<u32>
Get the country code digits
Sourcepub fn format(&self, format: PhoneFormat) -> String
pub fn format(&self, format: PhoneFormat) -> String
Format the phone number
Sourcepub fn is_landline(&self) -> bool
pub fn is_landline(&self) -> bool
Check if this number is a landline
Sourcepub fn is_toll_free(&self) -> bool
pub fn is_toll_free(&self) -> bool
Check if this number is toll-free
Trait Implementations§
Source§impl Clone for PhoneNumber
impl Clone for PhoneNumber
Source§fn clone(&self) -> PhoneNumber
fn clone(&self) -> PhoneNumber
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PhoneNumber
impl Debug for PhoneNumber
Source§impl Display for PhoneNumber
impl Display for PhoneNumber
Source§impl FromStr for PhoneNumber
impl FromStr for PhoneNumber
Source§impl Hash for PhoneNumber
impl Hash for PhoneNumber
Source§impl PartialEq for PhoneNumber
impl PartialEq for PhoneNumber
impl Eq for PhoneNumber
Auto Trait Implementations§
impl Freeze for PhoneNumber
impl RefUnwindSafe for PhoneNumber
impl Send for PhoneNumber
impl Sync for PhoneNumber
impl Unpin for PhoneNumber
impl UnwindSafe for PhoneNumber
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more