pub struct ResourceId(/* private fields */);Expand description
A validated SCIM resource identifier.
ResourceId represents a unique identifier for a SCIM resource. It enforces validation rules at construction time, ensuring that only valid resource IDs can exist in the system.
§Validation Rules
- Must not be empty
- Must be a valid string
- Additional format rules may be added in the future
§Examples
use scim_server::resource::value_objects::ResourceId;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Valid resource ID
let id = ResourceId::new("2819c223-7f76-453a-919d-413861904646".to_string())?;
println!("Resource ID: {}", id.as_str());
// Invalid resource ID - returns ValidationError
let invalid = ResourceId::new("".to_string());
assert!(invalid.is_err());
Ok(())
}Implementations§
Source§impl ResourceId
impl ResourceId
Sourcepub fn new(value: String) -> ValidationResult<Self>
pub fn new(value: String) -> ValidationResult<Self>
Create a new ResourceId with validation.
This is the primary constructor that enforces all validation rules. Use this method when creating ResourceId instances from untrusted input.
§Arguments
value- The string value to validate and wrap
§Returns
Ok(ResourceId)- If the value is validErr(ValidationError)- If the value violates validation rules
§Examples
use scim_server::resource::value_objects::ResourceId;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let id = ResourceId::new("user-123".to_string())?;
let empty_id = ResourceId::new("".to_string()); // Error
assert!(empty_id.is_err());
Ok(())
}Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Get the string representation of the ResourceId.
Returns a reference to the underlying string value. This is safe because the value is guaranteed to be valid by construction.
§Examples
use scim_server::resource::value_objects::ResourceId;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let id = ResourceId::new("test-id".to_string())?;
assert_eq!(id.as_str(), "test-id");
Ok(())
}Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Get the owned string value of the ResourceId.
Consumes the ResourceId and returns the underlying string. Use this when you need to transfer ownership of the string value.
§Examples
use scim_server::resource::value_objects::ResourceId;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let id = ResourceId::new("test-id".to_string())?;
let owned_string = id.into_string();
assert_eq!(owned_string, "test-id");
Ok(())
}Trait Implementations§
Source§impl Clone for ResourceId
impl Clone for ResourceId
Source§fn clone(&self) -> ResourceId
fn clone(&self) -> ResourceId
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ResourceId
impl Debug for ResourceId
Source§impl<'de> Deserialize<'de> for ResourceId
impl<'de> Deserialize<'de> for ResourceId
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 ResourceId
impl Display for ResourceId
Source§impl Hash for ResourceId
impl Hash for ResourceId
Source§impl PartialEq for ResourceId
impl PartialEq for ResourceId
Source§impl SchemaConstructible for ResourceId
impl SchemaConstructible for ResourceId
Source§fn from_schema_and_value(
definition: &AttributeDefinition,
value: &Value,
) -> ValidationResult<Self>
fn from_schema_and_value( definition: &AttributeDefinition, value: &Value, ) -> ValidationResult<Self>
Source§fn can_construct_from(definition: &AttributeDefinition) -> bool
fn can_construct_from(definition: &AttributeDefinition) -> bool
Source§fn constructor_priority() -> u8
fn constructor_priority() -> u8
Source§impl Serialize for ResourceId
impl Serialize for ResourceId
Source§impl TryFrom<&str> for ResourceId
Convert from &str to ResourceId with validation.
impl TryFrom<&str> for ResourceId
Convert from &str to ResourceId with validation.
Source§type Error = ValidationError
type Error = ValidationError
Source§fn try_from(value: &str) -> ValidationResult<Self>
fn try_from(value: &str) -> ValidationResult<Self>
Source§impl TryFrom<String> for ResourceId
Convert from String to ResourceId with validation.
impl TryFrom<String> for ResourceId
Convert from String to ResourceId with validation.