pub struct Address {
pub formatted: Option<String>,
pub street_address: Option<String>,
pub locality: Option<String>,
pub region: Option<String>,
pub postal_code: Option<String>,
pub country: Option<String>,
pub address_type: Option<String>,
pub primary: Option<bool>,
}Expand description
A validated SCIM address attribute.
Address represents a physical mailing address as defined in RFC 7643. It enforces validation rules at construction time, ensuring that only valid address attributes can exist in the system.
§Validation Rules
- At least one address component must be provided (not all fields can be empty/None)
- Individual address components cannot be empty strings
- Country code must be valid ISO 3166-1 “alpha-2” format when provided
- Type must be one of canonical values: “work”, “home”, “other” when provided
- Primary can only be true for one address in a collection
§Examples
use scim_server::resource::value_objects::Address;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create with full address components
let address = Address::new(
Some("100 Universal City Plaza\nHollywood, CA 91608 USA".to_string()),
Some("100 Universal City Plaza".to_string()),
Some("Hollywood".to_string()),
Some("CA".to_string()),
Some("91608".to_string()),
Some("US".to_string()),
Some("work".to_string()),
Some(true)
)?;
// Create with minimal components
let simple_address = Address::new_simple(
"123 Main St".to_string(),
"Anytown".to_string(),
"US".to_string()
)?;
Ok(())
}Fields§
§formatted: Option<String>§street_address: Option<String>§locality: Option<String>§region: Option<String>§postal_code: Option<String>§country: Option<String>§address_type: Option<String>§primary: Option<bool>Implementations§
Source§impl Address
impl Address
Sourcepub fn new(
formatted: Option<String>,
street_address: Option<String>,
locality: Option<String>,
region: Option<String>,
postal_code: Option<String>,
country: Option<String>,
address_type: Option<String>,
primary: Option<bool>,
) -> ValidationResult<Self>
pub fn new( formatted: Option<String>, street_address: Option<String>, locality: Option<String>, region: Option<String>, postal_code: Option<String>, country: Option<String>, address_type: Option<String>, primary: Option<bool>, ) -> ValidationResult<Self>
Create a new Address with all components.
This is the primary constructor that enforces all validation rules. Use this method when creating Address instances from untrusted input.
§Arguments
formatted- The full mailing address, formatted for displaystreet_address- The full street address componentlocality- The city or locality componentregion- The state or region componentpostal_code- The zip code or postal code componentcountry- The country name component (ISO 3166-1 alpha-2)address_type- The type of address (“work”, “home”, “other”)primary- Whether this is the primary address
§Returns
Ok(Address)- If at least one field is provided and all provided fields are validErr(ValidationError)- If all fields are None/empty or any field violates validation rules
Sourcepub fn new_simple(
street_address: String,
locality: String,
country: String,
) -> ValidationResult<Self>
pub fn new_simple( street_address: String, locality: String, country: String, ) -> ValidationResult<Self>
Create a simple Address with basic components.
Convenience constructor for creating basic address structures.
§Arguments
street_address- The street addresslocality- The city or localitycountry- The country code (ISO 3166-1 alpha-2)
§Returns
Ok(Address)- If the address components are validErr(ValidationError)- If any component violates validation rules
Sourcepub fn new_work(
street_address: String,
locality: String,
region: String,
postal_code: String,
country: String,
) -> ValidationResult<Self>
pub fn new_work( street_address: String, locality: String, region: String, postal_code: String, country: String, ) -> ValidationResult<Self>
Create a work Address.
Convenience constructor for work addresses.
§Arguments
street_address- The street addresslocality- The city or localityregion- The state or regionpostal_code- The postal codecountry- The country code (ISO 3166-1 alpha-2)
§Returns
Ok(Address)- If the address components are validErr(ValidationError)- If any component violates validation rules
Sourcepub fn formatted(&self) -> Option<&str>
pub fn formatted(&self) -> Option<&str>
Create an Address instance without validation for internal use.
This method bypasses validation and should only be used when the data is known to be valid, such as when deserializing from trusted sources.
§Safety
Get the formatted address.
Sourcepub fn street_address(&self) -> Option<&str>
pub fn street_address(&self) -> Option<&str>
Get the street address.
Sourcepub fn postal_code(&self) -> Option<&str>
pub fn postal_code(&self) -> Option<&str>
Get the postal code.
Sourcepub fn address_type(&self) -> Option<&str>
pub fn address_type(&self) -> Option<&str>
Get the address type.
Sourcepub fn is_primary(&self) -> bool
pub fn is_primary(&self) -> bool
Get whether this is the primary address.
Sourcepub fn display_address(&self) -> Option<String>
pub fn display_address(&self) -> Option<String>
Generate a formatted display address from components.
Creates a formatted address string from the available address components if no explicit formatted address is provided.
§Returns
The formatted address if available, otherwise a constructed address from components, or None if no meaningful components are available.