pub trait ScimPatchOperations: ResourceProvider {
// Required method
fn patch_error(&self, message: &str) -> Self::Error;
// Provided methods
fn apply_patch_operation(
&self,
resource_data: &mut Value,
operation: &Value,
) -> Result<(), Self::Error> { ... }
fn apply_add_operation(
&self,
resource_data: &mut Value,
path: Option<&str>,
value: Option<&Value>,
) -> Result<(), Self::Error> { ... }
fn apply_remove_operation(
&self,
resource_data: &mut Value,
path: Option<&str>,
) -> Result<(), Self::Error> { ... }
fn apply_replace_operation(
&self,
resource_data: &mut Value,
path: Option<&str>,
value: Option<&Value>,
) -> Result<(), Self::Error> { ... }
fn set_value_at_path(
&self,
data: &mut Value,
path: &str,
value: Value,
) -> Result<(), Self::Error> { ... }
fn remove_value_at_path(
&self,
data: &mut Value,
path: &str,
) -> Result<(), Self::Error> { ... }
fn remove_nested_value(
&self,
current: &mut Value,
parts: &[&str],
depth: usize,
) -> Result<(), Self::Error> { ... }
fn is_readonly_attribute(&self, path: &str) -> bool { ... }
fn is_valid_scim_path(&self, path: &str) -> bool { ... }
}Expand description
Trait providing RFC 7644 compliant PATCH operations for SCIM resources.
This trait extends ResourceProvider with PATCH functionality, implementing the complex logic for applying PATCH operations according to the SCIM specification. Most implementers can use the default implementations without modification.
Required Methods§
Sourcefn patch_error(&self, message: &str) -> Self::Error
fn patch_error(&self, message: &str) -> Self::Error
Create a PATCH-specific error.
Helper method for creating errors with appropriate context. Default implementation assumes the Error type can be created from strings. Override if your error type requires different construction.
Provided Methods§
Sourcefn apply_patch_operation(
&self,
resource_data: &mut Value,
operation: &Value,
) -> Result<(), Self::Error>
fn apply_patch_operation( &self, resource_data: &mut Value, operation: &Value, ) -> Result<(), Self::Error>
Apply a single PATCH operation to resource data.
This is the main entry point for PATCH operation processing. It validates the operation structure, checks for readonly attributes, and delegates to the appropriate operation handler.
§Arguments
resource_data- The resource JSON to modifyoperation- The PATCH operation as defined in RFC 7644
§Returns
Result indicating success or failure with appropriate error details
§Default Implementation
Provides full RFC 7644 compliance including:
- Operation validation (
opfield required) - Readonly attribute protection
- Delegation to appropriate operation handlers
Sourcefn apply_add_operation(
&self,
resource_data: &mut Value,
path: Option<&str>,
value: Option<&Value>,
) -> Result<(), Self::Error>
fn apply_add_operation( &self, resource_data: &mut Value, path: Option<&str>, value: Option<&Value>, ) -> Result<(), Self::Error>
Apply an ADD operation to resource data.
Implements RFC 7644 ADD operation semantics:
- With path: Sets value at the specified path
- Without path: Merges value with root object
- Handles multi-valued attributes appropriately
§Arguments
resource_data- The resource JSON to modifypath- Optional attribute pathvalue- Value to add (required for ADD operations)
Sourcefn apply_remove_operation(
&self,
resource_data: &mut Value,
path: Option<&str>,
) -> Result<(), Self::Error>
fn apply_remove_operation( &self, resource_data: &mut Value, path: Option<&str>, ) -> Result<(), Self::Error>
Apply a REMOVE operation to resource data.
Implements RFC 7644 REMOVE operation semantics:
- Removes the attribute or value at the specified path
- Handles complex path expressions
- Validates path before removal
§Arguments
resource_data- The resource JSON to modifypath- Attribute path to remove (required for REMOVE operations)
Sourcefn apply_replace_operation(
&self,
resource_data: &mut Value,
path: Option<&str>,
value: Option<&Value>,
) -> Result<(), Self::Error>
fn apply_replace_operation( &self, resource_data: &mut Value, path: Option<&str>, value: Option<&Value>, ) -> Result<(), Self::Error>
Apply a REPLACE operation to resource data.
Implements RFC 7644 REPLACE operation semantics:
- With path: Replaces value at specified path
- Without path: Replaces entire resource (merge semantics)
- Validates value before replacement
§Arguments
resource_data- The resource JSON to modifypath- Optional attribute pathvalue- Replacement value (required for REPLACE operations)
Sourcefn set_value_at_path(
&self,
data: &mut Value,
path: &str,
value: Value,
) -> Result<(), Self::Error>
fn set_value_at_path( &self, data: &mut Value, path: &str, value: Value, ) -> Result<(), Self::Error>
Set a value at a complex attribute path.
Handles SCIM attribute path expressions including:
- Simple attributes (e.g., “userName”)
- Complex attributes (e.g., “name.givenName”)
- Multi-valued attributes (e.g., “emails[type eq "work"].value”)
§Arguments
data- The JSON object to modifypath- The SCIM attribute pathvalue- The value to set
Sourcefn remove_value_at_path(
&self,
data: &mut Value,
path: &str,
) -> Result<(), Self::Error>
fn remove_value_at_path( &self, data: &mut Value, path: &str, ) -> Result<(), Self::Error>
Remove a value at a complex attribute path.
Handles removal of values from SCIM attribute paths, including validation and proper cleanup of empty parent objects.
§Arguments
data- The JSON object to modifypath- The SCIM attribute path to remove
Sourcefn remove_nested_value(
&self,
current: &mut Value,
parts: &[&str],
depth: usize,
) -> Result<(), Self::Error>
fn remove_nested_value( &self, current: &mut Value, parts: &[&str], depth: usize, ) -> Result<(), Self::Error>
Helper function to recursively remove nested values
Sourcefn is_readonly_attribute(&self, path: &str) -> bool
fn is_readonly_attribute(&self, path: &str) -> bool
Check if an attribute path refers to a readonly attribute.
Default implementation covers RFC 7644 readonly attributes:
id- Resource identifiermeta.created- Creation timestampmeta.resourceType- Resource typemeta.location- Resource location
Override this method to add custom readonly attributes.
Sourcefn is_valid_scim_path(&self, path: &str) -> bool
fn is_valid_scim_path(&self, path: &str) -> bool
Validate if a path represents a valid SCIM attribute.
Default implementation provides basic validation:
- Non-empty paths
- Valid attribute name characters
- Proper dot notation for complex attributes
Override for more sophisticated validation.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl<T> ScimPatchOperations for T
Default error creation for common error types that implement From