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: CountryCodeCLDR 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
impl PostalAddress
Sourcepub fn revision(&self) -> Option<i32>
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.
Sourcepub fn region_code(&self) -> CountryCode
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
impl PostalAddress
Sourcepub fn language_code(&self) -> &Option<Locale>
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”.
Sourcepub fn postal_code(&self) -> &Option<String>
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).
Sourcepub fn sorting_code(&self) -> &Option<String>
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).
Sourcepub fn administrative_area(&self) -> &Option<String>
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.
Sourcepub fn locality(&self) -> &Option<String>
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.
Sourcepub fn sublocality(&self) -> &Option<String>
pub fn sublocality(&self) -> &Option<String>
Sublocality of the address.
For example, this can be a neighborhood, borough, or district.
Sourcepub fn address_lines(&self) -> &Vec<String>
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).
Sourcepub fn recipients(&self) -> &Vec<String>
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.
Sourcepub fn organization(&self) -> &Option<String>
pub fn organization(&self) -> &Option<String>
The name of the organization at the address.
Source§impl PostalAddress
impl PostalAddress
Sourcepub const fn new(region_code: CountryCode) -> Self
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.
Sourcepub fn from_country_code(region_code: &str) -> Option<Self>
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.
Sourcepub fn has_address_lines(&self) -> bool
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.
Sourcepub fn has_recipients(&self) -> bool
pub fn has_recipients(&self) -> bool
Returns whether this address has any recipients specified.
Recipients represent who should receive mail at this address.
Sourcepub const fn get_region_code_str(&self) -> &str
pub const fn get_region_code_str(&self) -> &str
Gets the country code as a 2-letter string.
Sourcepub fn get_language_code_str(&self) -> Option<String>
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
impl Clone for PostalAddress
Source§fn clone(&self) -> PostalAddress
fn clone(&self) -> PostalAddress
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PostalAddress
impl Debug for PostalAddress
Source§impl<'de> Deserialize<'de> for PostalAddress
impl<'de> Deserialize<'de> for PostalAddress
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Hash for PostalAddress
impl Hash for PostalAddress
Source§impl PartialEq for PostalAddress
impl PartialEq for PostalAddress
Source§impl Serialize for PostalAddress
impl Serialize for PostalAddress
impl Eq for PostalAddress
impl StructuralPartialEq for PostalAddress
Auto Trait Implementations§
impl Freeze for PostalAddress
impl RefUnwindSafe for PostalAddress
impl Send for PostalAddress
impl Sync for PostalAddress
impl Unpin for PostalAddress
impl UnsafeUnpin for PostalAddress
impl UnwindSafe for PostalAddress
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.