Skip to main content

Address

Struct Address 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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

Source

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());
Source

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"));
Source

pub fn with_line2(self, value: impl Into<String>) -> Self

Fluent setter for line2.

Source

pub fn with_city(self, value: impl Into<String>) -> Self

Fluent setter for city.

Source

pub fn with_county(self, value: impl Into<String>) -> Self

Fluent setter for county.

Source

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"));
Source

pub fn with_country(self, value: impl Into<String>) -> Self

Fluent setter for country.

Trait Implementations§

Source§

impl Clone for Address

Source§

fn clone(&self) -> Address

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Address

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Address

Source§

fn default() -> Self

Identical to Address::new.

Source§

impl<'de> Deserialize<'de> for Address

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Address

Source§

fn eq(&self, other: &Address) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Address

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Address

Source§

impl StructuralPartialEq for Address

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,