#[non_exhaustive]pub struct Address {
pub line1: Option<String>,
pub line2: Option<String>,
pub city: Option<String>,
pub county: Option<String>,
pub postcode: Option<String>,
pub country: Option<String>,
}Expand description
Physical address used as supporting evidence in worker matcher.
All fields are Option<String> so partial addresses are first-class —
a record with only a postcode is still useful for matching.
The matcher does not weight every component equally; see
crate::matcher::MatchingEngine for the weighted comparison rules.
§Example
use worker_matcher::Address;
let mut addr = Address::new();
addr.line1 = Some("10 Downing Street".into());
addr.city = Some("London".into());
addr.postcode = Some("SW1A 2AA".into());
assert_eq!(addr.postcode.as_deref(), Some("SW1A 2AA"));
assert!(addr.country.is_none());Address is JSON round-trippable.
let mut a = Address::new();
a.postcode = Some("CF10 1AA".into());
let json = serde_json::to_string(&a).unwrap();
let back: Address = serde_json::from_str(&json).unwrap();
assert_eq!(a, back);Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.line1: Option<String>First line — typically house number and street, e.g. "10 Downing Street".
line2: Option<String>Second line — typically flat, locality, or care-of details.
city: Option<String>Town or city, e.g. "Cardiff".
county: Option<String>County or administrative region, e.g. "South Glamorgan".
postcode: Option<String>Postal code, e.g. "CF10 1AA". Compared after whitespace normalisation.
country: Option<String>Country, e.g. "Wales" or "United Kingdom".
Implementations§
Source§impl Address
impl Address
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct an empty address with every field set to None.
§Example
use worker_matcher::Address;
let a = Address::new();
assert!(a.line1.is_none());
assert!(a.postcode.is_none());Sourcepub fn with_line1(self, value: impl Into<String>) -> Self
pub fn with_line1(self, value: impl Into<String>) -> Self
Fluent setter for line1.
use worker_matcher::Address;
let a = Address::new().with_line1("10 Downing Street");
assert_eq!(a.line1.as_deref(), Some("10 Downing Street"));Sourcepub fn with_line2(self, value: impl Into<String>) -> Self
pub fn with_line2(self, value: impl Into<String>) -> Self
Fluent setter for line2.
Sourcepub fn with_county(self, value: impl Into<String>) -> Self
pub fn with_county(self, value: impl Into<String>) -> Self
Fluent setter for county.
Sourcepub fn with_postcode(self, value: impl Into<String>) -> Self
pub fn with_postcode(self, value: impl Into<String>) -> Self
Fluent setter for postcode.
use worker_matcher::Address;
let a = Address::new().with_postcode("CF10 1AA");
assert_eq!(a.postcode.as_deref(), Some("CF10 1AA"));Sourcepub fn with_country(self, value: impl Into<String>) -> Self
pub fn with_country(self, value: impl Into<String>) -> Self
Fluent setter for country.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Address
impl<'de> Deserialize<'de> for Address
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>,
impl Eq for Address
impl StructuralPartialEq for Address
Auto Trait Implementations§
impl Freeze for Address
impl RefUnwindSafe for Address
impl Send for Address
impl Sync for Address
impl Unpin for Address
impl UnsafeUnpin for Address
impl UnwindSafe for Address
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<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more