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::{
versioned::VersionedResource,
Resource,
};
use scim_server::resource::version::HttpVersion;
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: {}",
HttpVersion::from(versioned.version().clone())
);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::{
versioned::VersionedResource,
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: RawVersion) -> Self
pub fn with_version(resource: Resource, version: RawVersion) -> 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::{
versioned::VersionedResource,
Resource,
version::RawVersion,
};
use serde_json::json;
let resource = Resource::from_json("User".to_string(), json!({"id": "123"})).unwrap();
let version = RawVersion::from_hash("custom-version");
let versioned = VersionedResource::with_version(resource, version);Sourcepub fn version(&self) -> &RawVersion
pub fn version(&self) -> &RawVersion
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 get_id(&self) -> Option<&str>
pub fn get_id(&self) -> Option<&str>
Get the unique identifier of this resource.
Delegates to the inner resource’s get_id() method.
Sourcepub fn get_username(&self) -> Option<&str>
pub fn get_username(&self) -> Option<&str>
Get the userName field for User resources.
Delegates to the inner resource’s get_username() method.
Sourcepub fn get_external_id(&self) -> Option<&str>
pub fn get_external_id(&self) -> Option<&str>
Get the external id if present.
Delegates to the inner resource’s get_external_id() method.
Sourcepub fn get_meta(&self) -> Option<&Meta>
pub fn get_meta(&self) -> Option<&Meta>
Get the meta attributes if present.
Delegates to the inner resource’s get_meta() method.
Sourcepub fn get(&self, key: &str) -> Option<&Value>
pub fn get(&self, key: &str) -> Option<&Value>
Get an attribute value from the resource.
Delegates to the inner resource’s get() method.
Sourcepub fn get_attribute(&self, attribute_name: &str) -> Option<&Value>
pub fn get_attribute(&self, attribute_name: &str) -> Option<&Value>
Get an attribute value from the resource.
Delegates to the inner resource’s get_attribute() method.
This is an alias for get() for consistency with Resource API.
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::{
versioned::VersionedResource,
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() != &old_version);Sourcepub fn version_matches<F>(&self, expected: &ScimVersion<F>) -> bool
pub fn version_matches<F>(&self, expected: &ScimVersion<F>) -> 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 moreSource§impl Debug for VersionedResource
impl Debug for VersionedResource
Source§impl<'de> Deserialize<'de> for VersionedResource
impl<'de> Deserialize<'de> for VersionedResource
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>,
Auto Trait Implementations§
impl Freeze for VersionedResource
impl RefUnwindSafe for VersionedResource
impl Send for VersionedResource
impl Sync for VersionedResource
impl Unpin for VersionedResource
impl UnwindSafe for VersionedResource
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more