#[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
Postal address used as supporting evidence in event 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 event_matcher::Address;
let mut addr = Address::new();
addr.line1 = Some("Worthy Farm".into());
addr.city = Some("Pilton".into());
addr.postcode = Some("BA4 4BY".into());
assert_eq!(addr.postcode.as_deref(), Some("BA4 4BY"));
assert!(addr.country.is_none());Address is JSON round-trippable.
let mut a = Address::new();
a.postcode = Some("BA4 4BY".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. "Worthy Farm".
line2: Option<String>Second line — typically flat, locality, or care-of details.
city: Option<String>Town or city, e.g. "Pilton".
county: Option<String>County or administrative region, e.g. "Somerset".
postcode: Option<String>Postal code, e.g. "BA4 4BY". Compared after whitespace normalisation.
country: Option<String>Country, e.g. "England" 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 event_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.
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.
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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