Skip to main content

PostalAddress

Struct PostalAddress 

Source
pub struct PostalAddress {
    pub revision: Option<i32>,
    pub region_code: CountryCode,
    pub language_code: Option<Locale>,
    pub postal_code: Option<String>,
    pub sorting_code: Option<String>,
    pub administrative_area: Option<String>,
    pub locality: Option<String>,
    pub sublocality: Option<String>,
    pub address_lines: Vec<String>,
    pub recipients: Vec<String>,
    pub organization: Option<String>,
}
Expand description

Represents a postal address, such as for postal delivery or payments addresses.

With a postal address, a postal service can deliver items to a premise, P.O. box, or similar. A ostal address is not intended to model geographical locations like roads, towns, or mountains.

In typical usage, an address would be created by user input or from importing existing data, depending on the type of process.

§Advice on address input or editing:

  • Use an internationalization-ready address widget such as https://github.com/google/libaddressinput.

  • Users should not be presented with UI elements for input or editing of fields outside countries where that field is used.

For more guidance on how to use this schema, see: https://support.google.com/business/answer/6397478.

Fields§

§revision: Option<i32>

The schema revision of the PostalAddress. This must be set to 0, which is the latest revision.

All new revisions must be backward compatible with old revisions.

§region_code: CountryCode

CLDR region code of the country/region of the address.

This is never inferred and it is up to the user to ensure the value is correct. See http://cldr.unicode.org/ and http://www.unicode.org/cldr/charts/30/supplemental/territory_information.html for details. Example: “US” for United States.

§language_code: Option<Locale>

BCP-47 language code of the contents of this address (if known).

This is often the UI language of the input form or is expected to match one of the languages used in the address’ country/region, or their transliterated equivalents. This can affect formatting in certain countries, but is not critical to the correctness of the data and will never affect any validation or other non-formatting related operations.

If this value is not known, it should be omitted (rather than specifying a possibly incorrect default).

Examples: “zh-Hant”, “ja”, “ja-Latn”, “en”.

§postal_code: Option<String>

Postal code of the address.

Not all countries use or require postal codes to be present, but where they are used, they may trigger additional validation with other parts of the address (for example, state or zip code validation in the United States).

§sorting_code: Option<String>

Additional, country-specific, sorting code.

This is not used in most regions. Where it is used, the value is either a string like “CEDEX”, optionally followed by a number (for example, “CEDEX 7”), or just a number alone, representing the “sector code” (Jamaica), “delivery area indicator” (Malawi) or “post office indicator” (Côte d’Ivoire).

§administrative_area: Option<String>

Highest administrative subdivision which is used for postal addresses of a country or region.

For example, this can be a state, a province, an oblast, or a prefecture. For Spain, this is the province and not the autonomous community (for example, “Barcelona” and not “Catalonia”). Many countries don’t use an administrative area in postal addresses. For example, in Switzerland, this should be left unpopulated.

§locality: Option<String>

Generally refers to the city or town portion of the address.

Examples: US city, IT comune, UK post town. In regions of the world where localities are not well defined or do not fit into this structure well, leave locality empty and use address_lines.

§sublocality: Option<String>

Sublocality of the address.

For example, this can be a neighborhood, borough, or district.

§address_lines: Vec<String>

Unstructured address lines describing the lower levels of an address.

Because values in address_lines do not have type information and may sometimes contain multiple values in a single field (e.g. “Austin, TX”), it is important that the line order is clear. The order of address lines should be “envelope order” for the country/region of the address. In places where this can vary (e.g. Japan), address_validation can be used to provide hints in the address.

This format maintains compatibility with real-world addressing schemes which are sometimes flat and sometimes hierarchical.

The minimum permitted structural representation of an address consists of a region_code with all remaining information placed in the address_lines. It is possible to format such an address for display, but additional components cannot be extracted.

Creating an address only containing a region_code and address_lines, and then geocoding is the recommended way to handle completely unstructured addresses (as opposed to guessing which parts of the address should be localities or administrative areas).

§recipients: Vec<String>

The recipient at the address.

This field may, under certain circumstances, contain multiline information. For example, it might contain “care of” information.

§organization: Option<String>

The name of the organization at the address.

Implementations§

Source§

impl PostalAddress

Source

pub fn revision(&self) -> Option<i32>

The schema revision of the PostalAddress. This must be set to 0, which is the latest revision.

All new revisions must be backward compatible with old revisions.

Source

pub fn region_code(&self) -> CountryCode

CLDR region code of the country/region of the address.

This is never inferred and it is up to the user to ensure the value is correct. See http://cldr.unicode.org/ and http://www.unicode.org/cldr/charts/30/supplemental/territory_information.html for details. Example: “US” for United States.

Source§

impl PostalAddress

Source

pub fn language_code(&self) -> &Option<Locale>

BCP-47 language code of the contents of this address (if known).

This is often the UI language of the input form or is expected to match one of the languages used in the address’ country/region, or their transliterated equivalents. This can affect formatting in certain countries, but is not critical to the correctness of the data and will never affect any validation or other non-formatting related operations.

If this value is not known, it should be omitted (rather than specifying a possibly incorrect default).

Examples: “zh-Hant”, “ja”, “ja-Latn”, “en”.

Source

pub fn postal_code(&self) -> &Option<String>

Postal code of the address.

Not all countries use or require postal codes to be present, but where they are used, they may trigger additional validation with other parts of the address (for example, state or zip code validation in the United States).

Source

pub fn sorting_code(&self) -> &Option<String>

Additional, country-specific, sorting code.

This is not used in most regions. Where it is used, the value is either a string like “CEDEX”, optionally followed by a number (for example, “CEDEX 7”), or just a number alone, representing the “sector code” (Jamaica), “delivery area indicator” (Malawi) or “post office indicator” (Côte d’Ivoire).

Source

pub fn administrative_area(&self) -> &Option<String>

Highest administrative subdivision which is used for postal addresses of a country or region.

For example, this can be a state, a province, an oblast, or a prefecture. For Spain, this is the province and not the autonomous community (for example, “Barcelona” and not “Catalonia”). Many countries don’t use an administrative area in postal addresses. For example, in Switzerland, this should be left unpopulated.

Source

pub fn locality(&self) -> &Option<String>

Generally refers to the city or town portion of the address.

Examples: US city, IT comune, UK post town. In regions of the world where localities are not well defined or do not fit into this structure well, leave locality empty and use address_lines.

Source

pub fn sublocality(&self) -> &Option<String>

Sublocality of the address.

For example, this can be a neighborhood, borough, or district.

Source

pub fn address_lines(&self) -> &Vec<String>

Unstructured address lines describing the lower levels of an address.

Because values in address_lines do not have type information and may sometimes contain multiple values in a single field (e.g. “Austin, TX”), it is important that the line order is clear. The order of address lines should be “envelope order” for the country/region of the address. In places where this can vary (e.g. Japan), address_validation can be used to provide hints in the address.

This format maintains compatibility with real-world addressing schemes which are sometimes flat and sometimes hierarchical.

The minimum permitted structural representation of an address consists of a region_code with all remaining information placed in the address_lines. It is possible to format such an address for display, but additional components cannot be extracted.

Creating an address only containing a region_code and address_lines, and then geocoding is the recommended way to handle completely unstructured addresses (as opposed to guessing which parts of the address should be localities or administrative areas).

Source

pub fn recipients(&self) -> &Vec<String>

The recipient at the address.

This field may, under certain circumstances, contain multiline information. For example, it might contain “care of” information.

Source

pub fn organization(&self) -> &Option<String>

The name of the organization at the address.

Source§

impl PostalAddress

Source

pub const fn new(region_code: CountryCode) -> Self

Creates a new PostalAddress with the minimum required field.

Only region_code is required according to the specification.

Source

pub fn from_country_code(region_code: &str) -> Option<Self>

Creates a new PostalAddress from a country code string.

Returns an error if the country code is not a valid ISO 3166-1 alpha-2 code.

Source

pub fn has_address_lines(&self) -> bool

Returns whether this address has any address lines.

Address lines are the unstructured components that describe lower levels of the address when structured fields are not sufficient.

Source

pub fn has_recipients(&self) -> bool

Returns whether this address has any recipients specified.

Recipients represent who should receive mail at this address.

Source

pub const fn get_region_code_str(&self) -> &str

Gets the country code as a 2-letter string.

Source

pub fn get_language_code_str(&self) -> Option<String>

Gets the language code as a string if available.

Trait Implementations§

Source§

impl Clone for PostalAddress

Source§

fn clone(&self) -> PostalAddress

Returns a duplicate 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 PostalAddress

Source§

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

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

impl<'de> Deserialize<'de> for PostalAddress

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Hash for PostalAddress

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 PartialEq for PostalAddress

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Serialize for PostalAddress

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for PostalAddress

Source§

impl StructuralPartialEq for PostalAddress

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,