Struct ScimVersion

Source
pub struct ScimVersion { /* private fields */ }
Expand description

Opaque version identifier for SCIM resources.

Represents a version of a resource that can be used for optimistic concurrency control. The internal representation is opaque to prevent direct manipulation and ensure version consistency across different provider implementations.

Versions can be created from:

  • Provider-specific identifiers (database sequence numbers, timestamps, etc.)
  • Content hashes (for stateless version generation)
  • HTTP ETag headers (for parsing client-provided versions)

§Examples

use scim_server::resource::version::ScimVersion;

// From hash string
let version = ScimVersion::from_hash("12345");

// From content hash
let content = br#"{"id":"123","name":"John Doe"}"#;
let hash_version = ScimVersion::from_content(content);

// From HTTP ETag
let etag_version = ScimVersion::parse_http_header("\"abc123def\"").unwrap();

Implementations§

Source§

impl ScimVersion

Source

pub fn from_content(content: &[u8]) -> Self

Create a version from resource content.

This generates a deterministic hash-based version from the resource content, ensuring universal compatibility across all provider implementations. The version is based on the full resource content including all fields.

§Arguments
  • content - The complete resource content as bytes
§Examples
use scim_server::resource::version::ScimVersion;

let resource_json = br#"{"id":"123","userName":"john.doe"}"#;
let version = ScimVersion::from_content(resource_json);
Source

pub fn from_hash(hash_string: impl AsRef<str>) -> Self

Create a version from a pre-computed hash string.

This is useful for provider-specific versioning schemes such as database sequence numbers, timestamps, or UUIDs. The provider can use any string as a version identifier.

§Arguments
  • hash_string - Provider-specific version identifier
§Examples
use scim_server::resource::version::ScimVersion;

// Database sequence number
let db_version = ScimVersion::from_hash("seq_12345");

// Timestamp-based version
let time_version = ScimVersion::from_hash("1703123456789");

// UUID-based version
let uuid_version = ScimVersion::from_hash("550e8400-e29b-41d4-a716-446655440000");
§Examples
use scim_server::resource::version::ScimVersion;

let version = ScimVersion::from_hash("abc123def");
Source

pub fn parse_http_header(etag_header: &str) -> Result<Self, VersionError>

Parse a version from an HTTP ETag header value.

Accepts both weak and strong ETags as defined in RFC 7232. Weak ETags (prefixed with “W/”) are treated the same as strong ETags for SCIM resource versioning purposes.

§Arguments
  • etag_header - The ETag header value (e.g., “"abc123"” or “W/"abc123"”)
§Returns

The parsed version or an error if the ETag format is invalid

§Examples
use scim_server::resource::version::ScimVersion;

let version = ScimVersion::parse_http_header("\"abc123\"").unwrap();
let weak_version = ScimVersion::parse_http_header("W/\"abc123\"").unwrap();
Source

pub fn to_http_header(&self) -> String

Convert version to HTTP ETag header value.

This generates a weak HTTP ETag header value that can be used in conditional HTTP requests. SCIM resources use weak ETags since they represent semantic equivalence rather than byte-for-byte identity. The returned value includes the W/ prefix and surrounding quotes required by RFC 7232.

§Examples
use scim_server::resource::version::ScimVersion;

let version = ScimVersion::from_hash("12345");
let etag = version.to_http_header();
assert_eq!(etag, "W/\"12345\"");
Source

pub fn matches(&self, other: &ScimVersion) -> bool

Check if this version matches another version.

This is used for conditional operations to determine if the expected version matches the current version of a resource.

§Arguments
  • other - The version to compare against
§Examples
use scim_server::resource::version::ScimVersion;

let v1 = ScimVersion::from_hash("123");
let v2 = ScimVersion::from_hash("123");
let v3 = ScimVersion::from_hash("456");

assert!(v1.matches(&v2));
assert!(!v1.matches(&v3));
Source

pub fn as_str(&self) -> &str

Get the opaque version string.

This is primarily for internal use and debugging. The opaque string should not be relied upon for any business logic.

Trait Implementations§

Source§

impl Clone for ScimVersion

Source§

fn clone(&self) -> ScimVersion

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 ScimVersion

Source§

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

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

impl<'de> Deserialize<'de> for ScimVersion

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 Display for ScimVersion

Source§

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

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

impl Hash for ScimVersion

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ScimVersion

Source§

fn eq(&self, other: &ScimVersion) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ScimVersion

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

impl Eq for ScimVersion

Source§

impl StructuralPartialEq for ScimVersion

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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>,