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 more