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