pub struct PhoneNumber {
pub value: String,
pub display: Option<String>,
pub phone_type: Option<String>,
pub primary: Option<bool>,
}Expand description
A validated SCIM phone number attribute.
PhoneNumber represents a phone number as defined in RFC 7643. It enforces validation rules at construction time, ensuring that only valid phone number attributes can exist in the system.
§Validation Rules
- Phone number value cannot be empty
- Phone number should follow RFC 3966 format when possible (tel:+1-201-555-0123)
- Type must be one of canonical values: “work”, “home”, “mobile”, “fax”, “pager”, “other” when provided
- Display name is optional and used for human-readable representation
- Primary can only be true for one phone number in a collection
§Examples
use scim_server::resource::value_objects::PhoneNumber;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create with full phone number components
let phone = PhoneNumber::new(
"+1-201-555-0123".to_string(),
Some("Work Phone".to_string()),
Some("work".to_string()),
Some(true)
)?;
// Create with minimal components
let simple_phone = PhoneNumber::new_simple(
"+1-555-123-4567".to_string(),
"mobile".to_string()
)?;
Ok(())
}Fields§
§value: String§display: Option<String>§phone_type: Option<String>§primary: Option<bool>Implementations§
Source§impl PhoneNumber
impl PhoneNumber
Sourcepub fn new(
value: String,
display: Option<String>,
phone_type: Option<String>,
primary: Option<bool>,
) -> ValidationResult<Self>
pub fn new( value: String, display: Option<String>, phone_type: Option<String>, primary: Option<bool>, ) -> ValidationResult<Self>
Create a new PhoneNumber with all components.
This is the primary constructor that enforces all validation rules. Use this method when creating PhoneNumber instances from untrusted input.
§Arguments
value- The phone number value (preferably in RFC 3966 format)display- Optional human-readable display namephone_type- The type of phone number (“work”, “home”, “mobile”, etc.)primary- Whether this is the primary phone number
§Returns
Ok(PhoneNumber)- If the phone number is validErr(ValidationError)- If any field violates validation rules
Sourcepub fn new_simple(value: String, phone_type: String) -> ValidationResult<Self>
pub fn new_simple(value: String, phone_type: String) -> ValidationResult<Self>
Create a simple PhoneNumber with just value and type.
Convenience constructor for creating basic phone number structures.
§Arguments
value- The phone number valuephone_type- The type of phone number
§Returns
Ok(PhoneNumber)- If the phone number is validErr(ValidationError)- If any component violates validation rules
Sourcepub fn new_work(value: String) -> ValidationResult<Self>
pub fn new_work(value: String) -> ValidationResult<Self>
Sourcepub fn new_mobile(value: String) -> ValidationResult<Self>
pub fn new_mobile(value: String) -> ValidationResult<Self>
Sourcepub fn value(&self) -> &str
pub fn value(&self) -> &str
Create a PhoneNumber instance without validation for internal use. Get the phone number value.
Sourcepub fn phone_type(&self) -> Option<&str>
pub fn phone_type(&self) -> Option<&str>
Get the phone type.
Sourcepub fn is_primary(&self) -> bool
pub fn is_primary(&self) -> bool
Get whether this is the primary phone number.
Sourcepub fn display_value(&self) -> &str
pub fn display_value(&self) -> &str
Get a display-friendly representation of the phone number.
Returns the display name if available, otherwise the phone number value.
Sourcepub fn is_rfc3966_format(&self) -> bool
pub fn is_rfc3966_format(&self) -> bool
Check if this phone number uses RFC 3966 format.
Sourcepub fn to_rfc3966(&self) -> String
pub fn to_rfc3966(&self) -> String
Convert to RFC 3966 format if possible.
Attempts to convert the phone number to RFC 3966 format. This is a simple conversion that handles common cases.
Trait Implementations§
Source§impl Clone for PhoneNumber
impl Clone for PhoneNumber
Source§fn clone(&self) -> PhoneNumber
fn clone(&self) -> PhoneNumber
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PhoneNumber
impl Debug for PhoneNumber
Source§impl<'de> Deserialize<'de> for PhoneNumber
impl<'de> Deserialize<'de> for PhoneNumber
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for PhoneNumber
impl Display for PhoneNumber
Source§impl PartialEq for PhoneNumber
impl PartialEq for PhoneNumber
Source§impl Serialize for PhoneNumber
impl Serialize for PhoneNumber
impl Eq for PhoneNumber
impl StructuralPartialEq for PhoneNumber
Auto Trait Implementations§
impl Freeze for PhoneNumber
impl RefUnwindSafe for PhoneNumber
impl Send for PhoneNumber
impl Sync for PhoneNumber
impl Unpin for PhoneNumber
impl UnwindSafe for PhoneNumber
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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