MultiValuedAttribute

Struct MultiValuedAttribute 

Source
pub struct MultiValuedAttribute<T> { /* private fields */ }
Expand description

A generic container for multi-valued SCIM attributes.

This type provides type-safe handling of multi-valued attributes with support for designating one value as primary. It enforces the SCIM constraint that at most one value can be marked as primary.

§Type Parameters

  • T - The type of values contained in the multi-valued attribute

§Examples

use scim_server::resource::value_objects::{MultiValuedAttribute, EmailAddress};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let emails = vec![
        EmailAddress::new_simple("work@example.com".to_string())?,
        EmailAddress::new_simple("personal@example.com".to_string())?,
    ];

    let multi_emails = MultiValuedAttribute::new(emails)?;
    assert_eq!(multi_emails.len(), 2);
    assert!(multi_emails.primary().is_none());
    Ok(())
}

Implementations§

Source§

impl<T> MultiValuedAttribute<T>

Source

pub fn new(values: Vec<T>) -> ValidationResult<Self>

Creates a new multi-valued attribute from a collection of values.

§Arguments
  • values - Vector of values to store
§Returns
  • Ok(MultiValuedAttribute<T>) - Successfully created multi-valued attribute
  • Err(ValidationError) - If the input is invalid (e.g., empty vector)
§Examples
use scim_server::resource::value_objects::{MultiValuedAttribute, EmailAddress};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let emails = vec![
        EmailAddress::new_simple("work@example.com".to_string())?,
        EmailAddress::new_simple("personal@example.com".to_string())?,
    ];
    let multi_emails = MultiValuedAttribute::new(emails)?;
    Ok(())
}
Source

pub fn single(value: T) -> Self

Creates a new multi-valued attribute with a single value.

§Arguments
  • value - Single value to store
§Returns

A multi-valued attribute containing the single value

§Examples
use scim_server::resource::value_objects::{MultiValuedAttribute, EmailAddress};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let email = EmailAddress::new_simple("user@example.com".to_string())?;
    let multi_email = MultiValuedAttribute::single(email);
    assert_eq!(multi_email.len(), 1);
    Ok(())
}
Source

pub fn single_primary(value: T) -> Self

Creates a new multi-valued attribute with a single primary value.

§Arguments
  • value - Single value to store as primary
§Returns

A multi-valued attribute containing the single primary value

§Examples
use scim_server::resource::value_objects::{MultiValuedAttribute, EmailAddress};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let email = EmailAddress::new_simple("primary@example.com".to_string())?;
    let multi_email = MultiValuedAttribute::single_primary(email);
    assert!(multi_email.primary().is_some());
    Ok(())
}
Source

pub fn len(&self) -> usize

Returns the number of values in the collection.

§Examples
use scim_server::resource::value_objects::{MultiValuedAttribute, EmailAddress};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let emails = vec![
        EmailAddress::new_simple("work@example.com".to_string())?,
        EmailAddress::new_simple("personal@example.com".to_string())?,
    ];
    let multi_attr = MultiValuedAttribute::new(emails)?;
    assert_eq!(multi_attr.len(), 2);
    Ok(())
}
Source

pub fn is_empty(&self) -> bool

Returns true if the collection is empty.

§Examples
use scim_server::resource::value_objects::{MultiValuedAttribute, EmailAddress};

let multi_attr = MultiValuedAttribute::single(
    EmailAddress::new_simple("test@example.com".to_string()).unwrap()
);
assert!(!multi_attr.is_empty());
Source

pub fn primary(&self) -> Option<&T>

Returns a reference to the primary value, if one is set.

§Returns
  • Some(&T) - Reference to the primary value
  • None - No primary value is set
§Examples
use scim_server::resource::value_objects::{MultiValuedAttribute, EmailAddress};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let emails = vec![
        EmailAddress::new_simple("work@example.com".to_string())?,
        EmailAddress::new_simple("personal@example.com".to_string())?,
    ];
    let multi_attr = MultiValuedAttribute::new(emails)?.with_primary(0)?;
    if let Some(primary) = multi_attr.primary() {
        println!("Primary value found");
    }
    Ok(())
}
Source

pub fn primary_index(&self) -> Option<usize>

Returns the index of the primary value, if one is set.

§Returns
  • Some(usize) - Index of the primary value
  • None - No primary value is set
Source

pub fn values(&self) -> &[T]

Returns a reference to all values in the collection.

§Examples
use scim_server::resource::value_objects::{MultiValuedAttribute, EmailAddress};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let emails = vec![
        EmailAddress::new_simple("work@example.com".to_string())?,
        EmailAddress::new_simple("personal@example.com".to_string())?,
    ];
    let multi_attr = MultiValuedAttribute::new(emails)?;
    for value in multi_attr.values() {
        println!("Value: {:?}", value);
    }
    Ok(())
}
Source

pub fn get(&self, index: usize) -> Option<&T>

Returns a reference to the value at the specified index.

§Arguments
  • index - Index of the value to retrieve
§Returns
  • Some(&T) - Reference to the value at the index
  • None - Index is out of bounds
Source

pub fn with_primary(self, index: usize) -> ValidationResult<Self>

Creates a new multi-valued attribute with the specified value set as primary.

§Arguments
  • index - Index of the value to set as primary
§Returns
  • Ok(MultiValuedAttribute<T>) - New instance with primary value set
  • Err(ValidationError) - If the index is out of bounds
§Examples
use scim_server::resource::value_objects::{MultiValuedAttribute, EmailAddress};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let emails = vec![
        EmailAddress::new_simple("work@example.com".to_string())?,
        EmailAddress::new_simple("personal@example.com".to_string())?,
    ];
    let multi_attr = MultiValuedAttribute::new(emails)?;
    let with_primary = multi_attr.with_primary(0)?;
    assert!(with_primary.primary().is_some());
    Ok(())
}
Source

pub fn without_primary(self) -> Self

Creates a new multi-valued attribute with no primary value set.

§Examples
use scim_server::resource::value_objects::{MultiValuedAttribute, EmailAddress};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let emails = vec![
        EmailAddress::new_simple("work@example.com".to_string())?,
        EmailAddress::new_simple("personal@example.com".to_string())?,
    ];
    let multi_attr = MultiValuedAttribute::new(emails)?.with_primary(0)?;
    let without_primary = multi_attr.without_primary();
    assert!(without_primary.primary().is_none());
    Ok(())
}
Source

pub fn with_value(self, value: T) -> Self

Creates a new multi-valued attribute with an additional value.

§Arguments
  • value - Value to add to the collection
§Returns

A new multi-valued attribute with the added value

§Examples
use scim_server::resource::value_objects::{MultiValuedAttribute, EmailAddress};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let emails = vec![
        EmailAddress::new_simple("work@example.com".to_string())?,
    ];
    let multi_attr = MultiValuedAttribute::new(emails)?;
    let new_email = EmailAddress::new_simple("personal@example.com".to_string())?;
    let with_value = multi_attr.with_value(new_email);
    assert_eq!(with_value.len(), 2);
    Ok(())
}
Source

pub fn with_primary_value(self, value: T) -> Self

Creates a new multi-valued attribute with an additional primary value.

This method adds the value and sets it as the primary value.

§Arguments
  • value - Value to add as primary
§Returns

A new multi-valued attribute with the added primary value

§Examples
use scim_server::resource::value_objects::{MultiValuedAttribute, EmailAddress};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let emails = vec![
        EmailAddress::new_simple("work@example.com".to_string())?,
    ];
    let multi_attr = MultiValuedAttribute::new(emails)?;
    let new_email = EmailAddress::new_simple("primary@example.com".to_string())?;
    let with_primary = multi_attr.with_primary_value(new_email.clone());
    assert_eq!(with_primary.primary(), Some(&new_email));
    Ok(())
}
Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over the values in the collection.

§Examples
use scim_server::resource::value_objects::{MultiValuedAttribute, EmailAddress};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let emails = vec![
        EmailAddress::new_simple("work@example.com".to_string())?,
        EmailAddress::new_simple("personal@example.com".to_string())?,
    ];
    let multi_attr = MultiValuedAttribute::new(emails)?;
    for value in multi_attr.iter() {
        println!("Value: {:?}", value);
    }
    Ok(())
}
Source

pub fn validate_single_primary(&self) -> ValidationResult<()>

Validates that at most one value is marked as primary.

This method is primarily used internally to ensure invariants are maintained during construction and modification.

§Returns
  • Ok(()) - Validation passed
  • Err(ValidationError) - Multiple primary values detected
Source

pub fn find<P>(&self, predicate: P) -> Option<&T>
where P: Fn(&T) -> bool,

Finds the first value that matches the given predicate.

§Arguments
  • predicate - Function to test each value
§Returns
  • Some(&T) - Reference to the first matching value
  • None - No value matches the predicate
§Examples
use scim_server::resource::value_objects::{MultiValuedAttribute, EmailAddress};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let emails = vec![
        EmailAddress::new_simple("work@example.com".to_string())?,
        EmailAddress::new_simple("personal@example.com".to_string())?,
    ];
    let multi_attr = MultiValuedAttribute::new(emails)?;
    let found = multi_attr.find(|value| value.value().contains("work"));
    assert!(found.is_some());
    Ok(())
}
Source

pub fn filter<P>(&self, predicate: P) -> Vec<&T>
where P: Fn(&T) -> bool,

Returns all values that satisfy the given predicate. Filters values that match the given predicate.

§Arguments
  • predicate - Function to test each value
§Returns

An iterator over references to matching values

§Examples
use scim_server::resource::value_objects::{MultiValuedAttribute, EmailAddress};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let emails = vec![
        EmailAddress::new_simple("work@example.com".to_string())?,
        EmailAddress::new_simple("personal@example.com".to_string())?,
    ];
    let multi_attr = MultiValuedAttribute::new(emails)?;
    let work_values = multi_attr.filter(|v| v.value().contains("work"));
    assert_eq!(work_values.len(), 1);
    Ok(())
}
Source

pub fn into_values(self) -> Vec<T>

Converts the multi-valued attribute into a vector of values.

This consumes the multi-valued attribute and returns the underlying vector.

§Examples
use scim_server::resource::value_objects::{MultiValuedAttribute, EmailAddress};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let emails = vec![
        EmailAddress::new_simple("work@example.com".to_string())?,
        EmailAddress::new_simple("personal@example.com".to_string())?,
    ];
    let multi_attr = MultiValuedAttribute::new(emails)?;
    let values_vec = multi_attr.into_values();
    assert_eq!(values_vec.len(), 2);
    Ok(())
}

Trait Implementations§

Source§

impl<T: Clone> Clone for MultiValuedAttribute<T>

Source§

fn clone(&self) -> MultiValuedAttribute<T>

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<T: Debug> Debug for MultiValuedAttribute<T>

Source§

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

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

impl<T> Default for MultiValuedAttribute<T>

Source§

fn default() -> Self

Creates an empty multi-valued attribute.

Note: This creates an empty collection which may not be valid for all use cases. Use new() for validated construction.

Source§

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

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<T: Display> Display for MultiValuedAttribute<T>

Source§

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

Formats the multi-valued attribute for display.

Shows the number of values and indicates which one is primary.

Source§

impl<T> From<T> for MultiValuedAttribute<T>

Source§

fn from(value: T) -> Self

Creates a multi-valued attribute from a single value.

Source§

impl<T> From<Vec<T>> for MultiValuedAttribute<T>

Source§

fn from(values: Vec<T>) -> Self

Creates a multi-valued attribute from a vector of values.

This bypasses validation and should be used carefully. Consider using new() for validated construction.

Source§

impl<'a, T> IntoIterator for &'a MultiValuedAttribute<T>

Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator that yields borrowed values.

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

impl<T> IntoIterator for MultiValuedAttribute<T>

Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator that yields owned values.

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

impl<T: PartialEq> PartialEq for MultiValuedAttribute<T>

Source§

fn eq(&self, other: &MultiValuedAttribute<T>) -> 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<T> Serialize for MultiValuedAttribute<T>
where T: Serialize,

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<T> StructuralPartialEq for MultiValuedAttribute<T>

Auto Trait Implementations§

§

impl<T> Freeze for MultiValuedAttribute<T>

§

impl<T> RefUnwindSafe for MultiValuedAttribute<T>
where T: RefUnwindSafe,

§

impl<T> Send for MultiValuedAttribute<T>
where T: Send,

§

impl<T> Sync for MultiValuedAttribute<T>
where T: Sync,

§

impl<T> Unpin for MultiValuedAttribute<T>
where T: Unpin,

§

impl<T> UnwindSafe for MultiValuedAttribute<T>
where T: UnwindSafe,

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<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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

Source§

impl<T> ErasedDestructor for T
where T: 'static,