pub struct Name {
pub formatted: Option<String>,
pub family_name: Option<String>,
pub given_name: Option<String>,
pub middle_name: Option<String>,
pub honorific_prefix: Option<String>,
pub honorific_suffix: Option<String>,
}Expand description
A validated SCIM name attribute.
Name represents the components of a user’s real name as defined in RFC 7643. It enforces validation rules at construction time, ensuring that only valid name attributes can exist in the system.
§Validation Rules
- At least one name component must be provided (not all fields can be empty/None)
- Individual name components cannot be empty strings
- All fields are optional but if provided must contain meaningful content
§Examples
use scim_server::resource::value_objects::Name;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create with full name components
let name = Name::new(
Some("Ms. Barbara J Jensen, III".to_string()),
Some("Jensen".to_string()),
Some("Barbara".to_string()),
Some("Jane".to_string()),
Some("Ms.".to_string()),
Some("III".to_string())
)?;
// Create with minimal components
let simple_name = Name::new_simple(
"John".to_string(),
"Doe".to_string()
)?;
Ok(())
}Fields§
§formatted: Option<String>§family_name: Option<String>§given_name: Option<String>§middle_name: Option<String>§honorific_prefix: Option<String>§honorific_suffix: Option<String>Implementations§
Source§impl Name
impl Name
Sourcepub fn new(
formatted: Option<String>,
family_name: Option<String>,
given_name: Option<String>,
middle_name: Option<String>,
honorific_prefix: Option<String>,
honorific_suffix: Option<String>,
) -> ValidationResult<Self>
pub fn new( formatted: Option<String>, family_name: Option<String>, given_name: Option<String>, middle_name: Option<String>, honorific_prefix: Option<String>, honorific_suffix: Option<String>, ) -> ValidationResult<Self>
Create a new Name with all components.
This is the primary constructor that enforces all validation rules. Use this method when creating Name instances from untrusted input.
§Arguments
formatted- The full name, formatted for displayfamily_name- The family name or last namegiven_name- The given name or first namemiddle_name- The middle name(s)honorific_prefix- The honorific prefix or title (e.g., “Ms.”, “Dr.”)honorific_suffix- The honorific suffix (e.g., “III”, “Jr.”)
§Returns
Ok(Name)- 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(
given_name: String,
family_name: String,
) -> ValidationResult<Self>
pub fn new_simple( given_name: String, family_name: String, ) -> ValidationResult<Self>
Create a simple Name with just given and family names.
Convenience constructor for creating basic name structures.
§Arguments
given_name- The given name or first namefamily_name- The family name or last name
§Returns
Ok(Name)- If the names are validErr(ValidationError)- If any name violates validation rules
Sourcepub fn new_formatted(formatted: String) -> ValidationResult<Self>
pub fn new_formatted(formatted: String) -> ValidationResult<Self>
Sourcepub fn formatted(&self) -> Option<&str>
pub fn formatted(&self) -> Option<&str>
Create a Name instance without validation for internal use. Get the formatted name.
Sourcepub fn family_name(&self) -> Option<&str>
pub fn family_name(&self) -> Option<&str>
Get the family name.
Sourcepub fn given_name(&self) -> Option<&str>
pub fn given_name(&self) -> Option<&str>
Get the given name.
Sourcepub fn middle_name(&self) -> Option<&str>
pub fn middle_name(&self) -> Option<&str>
Get the middle name.
Sourcepub fn honorific_prefix(&self) -> Option<&str>
pub fn honorific_prefix(&self) -> Option<&str>
Get the honorific prefix.
Sourcepub fn honorific_suffix(&self) -> Option<&str>
pub fn honorific_suffix(&self) -> Option<&str>
Get the honorific suffix.
Sourcepub fn display_name(&self) -> Option<String>
pub fn display_name(&self) -> Option<String>
Generate a formatted display name from components.
Creates a formatted name string from the available name components if no explicit formatted name is provided.
§Returns
The formatted name if available, otherwise a constructed name from components, or None if no components are available.
Sourcepub fn from_json(value: &Value) -> ValidationResult<Self>
pub fn from_json(value: &Value) -> ValidationResult<Self>
Create a Name from a JSON value.