Struct Address

Source
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

Source

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 display
  • street_address - The full street address component
  • locality - The city or locality component
  • region - The state or region component
  • postal_code - The zip code or postal code component
  • country - 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 valid
  • Err(ValidationError) - If all fields are None/empty or any field violates validation rules
Source

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 address
  • locality - The city or locality
  • country - The country code (ISO 3166-1 alpha-2)
§Returns
  • Ok(Address) - If the address components are valid
  • Err(ValidationError) - If any component violates validation rules
Source

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 address
  • locality - The city or locality
  • region - The state or region
  • postal_code - The postal code
  • country - The country code (ISO 3166-1 alpha-2)
§Returns
  • Ok(Address) - If the address components are valid
  • Err(ValidationError) - If any component violates validation rules
Source

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.

Source

pub fn street_address(&self) -> Option<&str>

Get the street address.

Source

pub fn locality(&self) -> Option<&str>

Get the locality.

Source

pub fn region(&self) -> Option<&str>

Get the region.

Source

pub fn postal_code(&self) -> Option<&str>

Get the postal code.

Source

pub fn country(&self) -> Option<&str>

Get the country code.

Source

pub fn address_type(&self) -> Option<&str>

Get the address type.

Source

pub fn is_primary(&self) -> bool

Get whether this is the primary address.

Source

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.

Source

pub fn is_empty(&self) -> bool

Check if the address has any meaningful content.

Trait Implementations§

Source§

impl Clone for Address

Source§

fn clone(&self) -> Address

Returns a duplicate of the value. Read more
1.0.0 · 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<'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 Display for Address

Source§

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

Formats the value using the given formatter. 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 · 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> TenantValidator for T

Source§

fn validate_tenant_context( &self, expected_tenant_id: &str, context: &RequestContext, ) -> Result<(), String>

Validate that the context has the expected tenant.
Source§

fn validate_single_tenant_context( &self, context: &RequestContext, ) -> Result<(), String>

Validate that the context is for single-tenant operation.
Source§

fn require_tenant_context(&self, context: &RequestContext) -> Result<(), String>

Extract tenant context or return error for multi-tenant operations.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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>,