VersionedResource

Struct VersionedResource 

Source
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

Source

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);
Source

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 resource
  • version - 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);
Source

pub fn resource(&self) -> &Resource

Get the resource data.

Source

pub fn version(&self) -> &ScimVersion

Get the resource version.

Source

pub fn into_resource(self) -> Resource

Convert into the underlying resource, discarding version information.

Source

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));
Source

pub fn version_matches(&self, expected: &ScimVersion) -> bool

Check if this resource’s version matches the expected version.

§Arguments
  • expected - The expected version to check against
§Returns

true if versions match, false otherwise

Source

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

Source§

fn clone(&self) -> VersionedResource

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VersionedResource

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for VersionedResource

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for VersionedResource

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> TenantValidator for T

Source§

fn validate_tenant_context( &self, expected_tenant_id: &str, context: &RequestContext, ) -> Result<(), String>

Validate that the context has the expected tenant.
Source§

fn validate_single_tenant_context( &self, context: &RequestContext, ) -> Result<(), String>

Validate that the context is for single-tenant operation.
Source§

fn require_tenant_context(&self, context: &RequestContext) -> Result<(), String>

Extract tenant context or return error for multi-tenant operations.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,