pub struct VersionedResource { /* private fields */ }Expand description
A resource with its associated version information.
This wrapper combines a SCIM resource with its version, enabling conditional operations that can detect concurrent modifications. The version is automatically computed from the resource content.
§Examples
use scim_server::resource::{
conditional_provider::VersionedResource,
core::Resource,
};
use serde_json::json;
let resource = Resource::from_json("User".to_string(), json!({
"id": "123",
"userName": "john.doe",
"active": true
})).unwrap();
let versioned = VersionedResource::new(resource);
println!("Resource version: {}", versioned.version().to_http_header());Implementations§
Source§impl VersionedResource
impl VersionedResource
Sourcepub fn new(resource: Resource) -> Self
pub fn new(resource: Resource) -> Self
Create a new versioned resource.
The version is automatically computed from the resource’s JSON representation, ensuring consistency across all provider implementations.
§Arguments
resource- The SCIM resource
§Examples
use scim_server::resource::{
conditional_provider::VersionedResource,
core::Resource,
};
use serde_json::json;
let resource = Resource::from_json("User".to_string(), json!({
"id": "123",
"userName": "john.doe"
})).unwrap();
let versioned = VersionedResource::new(resource);Sourcepub fn with_version(resource: Resource, version: ScimVersion) -> Self
pub fn with_version(resource: Resource, version: ScimVersion) -> Self
Create a versioned resource with a specific version.
This is useful when migrating from existing systems or when the version needs to be preserved from external sources.
§Arguments
resource- The SCIM resourceversion- The specific version to use
§Examples
use scim_server::resource::{
conditional_provider::VersionedResource,
core::Resource,
version::ScimVersion,
};
use serde_json::json;
let resource = Resource::from_json("User".to_string(), json!({"id": "123"})).unwrap();
let version = ScimVersion::from_hash("custom-version");
let versioned = VersionedResource::with_version(resource, version);Sourcepub fn version(&self) -> &ScimVersion
pub fn version(&self) -> &ScimVersion
Get the resource version.
Sourcepub fn into_resource(self) -> Resource
pub fn into_resource(self) -> Resource
Convert into the underlying resource, discarding version information.
Sourcepub fn update_resource(&mut self, new_resource: Resource)
pub fn update_resource(&mut self, new_resource: Resource)
Update the resource content and recompute the version.
This ensures the version always reflects the current resource state.
§Arguments
new_resource- The updated resource data
§Examples
use scim_server::resource::{
conditional_provider::VersionedResource,
core::Resource,
};
use serde_json::json;
let resource = Resource::from_json("User".to_string(), json!({"id": "123", "active": true})).unwrap();
let mut versioned = VersionedResource::new(resource);
let updated = Resource::from_json("User".to_string(), json!({"id": "123", "active": false})).unwrap();
let old_version = versioned.version().clone();
versioned.update_resource(updated);
assert!(!versioned.version().matches(&old_version));Sourcepub fn version_matches(&self, expected: &ScimVersion) -> bool
pub fn version_matches(&self, expected: &ScimVersion) -> bool
Sourcepub fn refresh_version(&mut self)
pub fn refresh_version(&mut self)
Refresh the version based on current resource content.
This is useful if the resource was modified externally and the version needs to be synchronized.
Trait Implementations§
Source§impl Clone for VersionedResource
impl Clone for VersionedResource
Source§fn clone(&self) -> VersionedResource
fn clone(&self) -> VersionedResource
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more