pub struct Address {
pub line1: String,
pub line2: Option<String>,
pub city: String,
pub county: Option<String>,
pub postcode: UkPostcode,
pub country: CountryCode,
pub coords: Option<Coords>,
}Expand description
A validated postal address.
Validation:
line1must be non-empty after trimmingcitymust be non-empty after trimmingpostcodemust be valid (already validated by its type)countrymust be validline2andcountyifSomemust be non-empty after trimming- optional
coordsifSomemust be valid
Fields§
§line1: StringFirst address line (required, non-empty).
line2: Option<String>Optional second address line.
city: StringCity / town (required, non-empty).
county: Option<String>Optional county / state / province.
postcode: UkPostcodePostcode / ZIP.
country: CountryCodeISO 3166-1 alpha-2 country code.
coords: Option<Coords>Optional coordinates.
Implementations§
Source§impl Address
impl Address
Sourcepub fn new(
line1: String,
line2: Option<String>,
city: String,
county: Option<String>,
postcode: UkPostcode,
country: CountryCode,
) -> Result<Self, GeoError>
pub fn new( line1: String, line2: Option<String>, city: String, county: Option<String>, postcode: UkPostcode, country: CountryCode, ) -> Result<Self, GeoError>
Create a validated address.
Validates that required string fields are non-empty after trimming and that optional string fields, if present, are non-empty after trimming.
§Errors
Returns GeoError::InvalidAddress if validation fails.
Sourcepub fn new_with_coords(
line1: String,
line2: Option<String>,
city: String,
county: Option<String>,
postcode: UkPostcode,
country: CountryCode,
coords: Option<Coords>,
) -> Result<Self, GeoError>
pub fn new_with_coords( line1: String, line2: Option<String>, city: String, county: Option<String>, postcode: UkPostcode, country: CountryCode, coords: Option<Coords>, ) -> Result<Self, GeoError>
Create a validated address with optional coordinates.
§Errors
Returns GeoError::InvalidAddress if validation fails or GeoError::InvalidCoords via
address error conversion if coords are invalid (coords are already validated on construction).
Sourcepub fn postcode(&self) -> &UkPostcode
pub fn postcode(&self) -> &UkPostcode
Return postcode.
Sourcepub fn country(&self) -> &CountryCode
pub fn country(&self) -> &CountryCode
Return country.
Trait Implementations§
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
Mutably borrows from an owned value. Read more