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::{
    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

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

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

pub fn resource(&self) -> &Resource

Get the resource data.

Source

pub fn version(&self) -> &RawVersion

Get the resource version.

Source

pub fn into_resource(self) -> Resource

Convert into the underlying resource, discarding version information.

Source

pub fn get_id(&self) -> Option<&str>

Get the unique identifier of this resource.

Delegates to the inner resource’s get_id() method.

Source

pub fn get_username(&self) -> Option<&str>

Get the userName field for User resources.

Delegates to the inner resource’s get_username() method.

Source

pub fn get_external_id(&self) -> Option<&str>

Get the external id if present.

Delegates to the inner resource’s get_external_id() method.

Source

pub fn get_meta(&self) -> Option<&Meta>

Get the meta attributes if present.

Delegates to the inner resource’s get_meta() method.

Source

pub fn get(&self, key: &str) -> Option<&Value>

Get an attribute value from the resource.

Delegates to the inner resource’s get() method.

Source

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.

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

pub fn version_matches<F>(&self, expected: &ScimVersion<F>) -> 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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

Source§

impl<T> ErasedDestructor for T
where T: 'static,