Struct phonenumber::metadata::Format

source ·
pub struct Format { /* private fields */ }
Expand description

Description of a phone number format.

Implementations§

source§

impl Format

source

pub fn pattern(&self) -> &CachedRegex

A regex that is used to match the national (significant) number. For example, the pattern “(20)(\d{4})(\d{4})” will match number “2070313000”, which is the national (significant) number for Google London.

Note the presence of the parentheses, which are capturing groups what specifies the grouping of numbers.

source

pub fn format(&self) -> &str

Specifies how the national (significant) number matched by pattern should be formatted.

Using the same example as above, format could contain “$1 $2 $3”, meaning that the number should be formatted as “20 7031 3000”.

Each $x are replaced by the numbers captured by group x in the regex specified by pattern.

source

pub fn leading_digits(&self) -> &[CachedRegex]

A regex that is used to match a certain number of digits at the beginning of the national (significant) number. When the match is successful, the accompanying pattern and format should be used to format this number. For example, if leading_digits=“[1-3]|44”, then all the national numbers starting with 1, 2, 3 or 44 should be formatted using the accompanying pattern and format.

The first leadingDigitsPattern matches up to the first three digits of the national (significant) number; the next one matches the first four digits, then the first five and so on, until the leadingDigitsPattern can uniquely identify one pattern and format to be used to format the number.

In the case when only one formatting pattern exists, no leading_digits_pattern is needed.

source

pub fn national_prefix(&self) -> Option<&str>

Specifies how the national prefix ($NP) together with the first group ($FG) in the national significant number should be formatted in the NATIONAL format when a national prefix exists for a certain country.

For example, when this field contains “($NP$FG)”, a number from Beijing, China (whose $NP = 0), which would by default be formatted without national prefix as 10 1234 5678 in NATIONAL format, will instead be formatted as (010) 1234 5678; to format it as (0)10 1234 5678, the field would contain “($NP)$FG”. Note $FG should always be present in this field, but $NP can be omitted. For example, having “$FG” could indicate the number should be formatted in NATIONAL format without the national prefix.

This is commonly used to override the rule specified for the territory in the XML file.

When this field is missing, a number will be formatted without national prefix in NATIONAL format. This field does not affect how a number is formatted in other formats, such as INTERNATIONAL.

source

pub fn is_national_prefix_optional(&self) -> bool

Whether the national prefix is optional when formatting.

source

pub fn domestic_carrier(&self) -> Option<&str>

Specifies how any carrier code ($CC) together with the first group ($FG) in the national significant number should be formatted when formatWithCarrierCode is called, if carrier codes are used for a certain country.

Trait Implementations§

source§

impl Clone for Format

source§

fn clone(&self) -> Format

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Format

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Format

§

impl RefUnwindSafe for Format

§

impl Send for Format

§

impl Sync for Format

§

impl Unpin for Format

§

impl UnwindSafe for Format

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.