pub struct PhoneNumber(/* private fields */);
Expand description
This crate provides functionality to parse and validate phone numbers with country codes.
§Example
use custom_type::{PhoneNumber, CountryCode};
let phone_number = PhoneNumber::parse(CountryCode::USA, "1234567890").unwrap();
println!("{}", phone_number);
§Features
- Parse and validate phone numbers with a specified country code.
- Custom error type
TypeError
for handling invalid phone numbers.
§PhoneNumber : Parse impl ToString
Into a Valid Phone Number
Provides a method to parse and validate phone numbers with specified country codes.
Implementations§
Source§impl PhoneNumber
impl PhoneNumber
Sourcepub fn parse(
country_code: CountryCode,
phone_number: impl ToString,
) -> Result<Self, TypeError>
pub fn parse( country_code: CountryCode, phone_number: impl ToString, ) -> Result<Self, TypeError>
Parses a given string into a phone number with the specified country code.
A valid phone number must be between 10 to 15 digits long.
§Arguments
country_code
- The country code to be prepended to the phone number.phone_number
- A string slice that holds the phone number to be parsed.
§Returns
Ok(Self)
if the phone number meets the criteria.Err(TypeError::ParseError)
if the phone number is invalid.
§Examples
use custom_type::{PhoneNumber, CountryCode};
let phone_number = PhoneNumber::parse(CountryCode::USA, "1234567890");
assert!(phone_number.is_ok());
let invalid_phone_number = PhoneNumber::parse(CountryCode::USA, "12345");
assert!(invalid_phone_number.is_err());
Trait Implementations§
Source§impl Debug for PhoneNumber
impl Debug for PhoneNumber
Source§impl Display for PhoneNumber
impl Display for PhoneNumber
Source§impl PartialEq for PhoneNumber
impl PartialEq for PhoneNumber
impl StructuralPartialEq 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