proto_types/common/postal_address.rs
1use crate::common::PostalAddress;
2
3impl PostalAddress {
4 /// Checks if this [`PostalAddress`]'s `region_code` is empty. If it is, it means that the instance is invalid.
5 pub fn has_region_code(&self) -> bool {
6 !self.region_code.is_empty()
7 }
8
9 /// Checks if the `region_code` of this address matches the given `code`.
10 /// The `code` should be a CLDR region code (ISO 3166-1 alpha-2, e.g., "US", "CH").
11 pub fn matches_region_code(&self, code: &str) -> bool {
12 self.region_code == code
13 }
14
15 /// Checks if the `language_code` of this address matches the given BCP-47 `code`.
16 /// The `code` should be a BCP-44 language tag (e.g., "en-US", "ja").
17 pub fn has_language_code(&self, code: &str) -> bool {
18 self.language_code == code
19 }
20
21 /// Checks if the `postal_code` of this address matches the given `code`.
22 pub fn has_postal_code(&self, code: &str) -> bool {
23 self.postal_code == code
24 }
25
26 /// Checks if the `sorting_code` of this address matches the given `code`.
27 pub fn has_sorting_code(&self, code: &str) -> bool {
28 self.sorting_code == code
29 }
30
31 /// Checks if the `administrative_area` of this address matches the given `name`.
32 pub fn has_administrative_area(&self, name: &str) -> bool {
33 self.administrative_area == name
34 }
35
36 /// Checks if the `locality` (city/town) of this address matches the given `name`.
37 pub fn has_locality(&self, name: &str) -> bool {
38 self.locality == name
39 }
40
41 /// Checks if the `sublocality` of this address matches the given `name`.
42 pub fn has_sublocality(&self, name: &str) -> bool {
43 self.sublocality == name
44 }
45}