Skip to main content

NumberFormat

Struct NumberFormat 

Source
pub struct NumberFormat {
    pub pattern: String,
    pub format: String,
    pub leading_digits_pattern: Vec<String>,
    pub national_prefix_formatting_rule: Option<String>,
    pub national_prefix_optional_when_formatting: Option<bool>,
    pub domestic_carrier_code_formatting_rule: Option<String>,
}

Fields§

§pattern: String
👎Deprecated:

This field is shadowed by the wrapper and is intentionally left empty. Access the underlying data via .original.

pattern is 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.

§format: String

format 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.

§leading_digits_pattern: Vec<String>
👎Deprecated:

This field is shadowed by the wrapper and is intentionally left empty. Access the underlying data via .original.

This field is 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.

§national_prefix_formatting_rule: Option<String>

This field 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.

§national_prefix_optional_when_formatting: Option<bool>

This field specifies whether the $NP can be omitted when formatting a number in national format, even though it usually wouldn’t be. For example, a UK number would be formatted by our library as 020 XXXX XXXX. If we have commonly seen this number written by people without the leading 0, for example as (20) XXXX XXXX, this field would be set to true. This will be inherited from the value set for the territory in the XML file, unless a national_prefix_optional_when_formatting is defined specifically for this NumberFormat.

§domestic_carrier_code_formatting_rule: Option<String>

This field 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.

Implementations§

Source§

impl NumberFormat

Source

pub fn national_prefix_formatting_rule(&self) -> &str

Returns the value of national_prefix_formatting_rule, or the default value if national_prefix_formatting_rule is unset.

Source

pub fn domestic_carrier_code_formatting_rule(&self) -> &str

Returns the value of domestic_carrier_code_formatting_rule, or the default value if domestic_carrier_code_formatting_rule is unset.

Source

pub fn national_prefix_optional_when_formatting(&self) -> bool

Returns the value of national_prefix_optional_when_formatting, or the default value if national_prefix_optional_when_formatting is unset.

Trait Implementations§

Source§

impl Clone for NumberFormat

Source§

fn clone(&self) -> NumberFormat

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for NumberFormat

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for NumberFormat

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Hash for NumberFormat

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Message for NumberFormat

Source§

fn encoded_len(&self) -> usize

Returns the encoded length of the message without a length delimiter.
Source§

fn clear(&mut self)

Clears the message, resetting all fields to their default.
Source§

fn encode(&self, buf: &mut impl BufMut) -> Result<(), EncodeError>
where Self: Sized,

Encodes the message to a buffer. Read more
Source§

fn encode_to_vec(&self) -> Vec<u8>
where Self: Sized,

Encodes the message to a newly allocated buffer.
Source§

fn encode_length_delimited( &self, buf: &mut impl BufMut, ) -> Result<(), EncodeError>
where Self: Sized,

Encodes the message with a length-delimiter to a buffer. Read more
Source§

fn encode_length_delimited_to_vec(&self) -> Vec<u8>
where Self: Sized,

Encodes the message with a length-delimiter to a newly allocated buffer.
Source§

fn decode(buf: impl Buf) -> Result<Self, DecodeError>
where Self: Default,

Decodes an instance of the message from a buffer. Read more
Source§

fn decode_length_delimited(buf: impl Buf) -> Result<Self, DecodeError>
where Self: Default,

Decodes a length-delimited instance of the message from the buffer.
Source§

fn merge(&mut self, buf: impl Buf) -> Result<(), DecodeError>
where Self: Sized,

Decodes an instance of the message from a buffer, and merges it into self. Read more
Source§

fn merge_length_delimited(&mut self, buf: impl Buf) -> Result<(), DecodeError>
where Self: Sized,

Decodes a length-delimited instance of the message from buffer, and merges it into self.
Source§

impl PartialEq for NumberFormat

Source§

fn eq(&self, other: &NumberFormat) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for NumberFormat

Source§

impl StructuralPartialEq for NumberFormat

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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>,

Source§

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.