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
impl ScimVersion
Sourcepub fn from_content(content: &[u8]) -> Self
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);Sourcepub fn from_hash(hash_string: impl AsRef<str>) -> Self
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");Sourcepub fn parse_http_header(etag_header: &str) -> Result<Self, VersionError>
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();Sourcepub fn to_http_header(&self) -> String
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\"");Sourcepub fn matches(&self, other: &ScimVersion) -> bool
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));Trait Implementations§
Source§impl Clone for ScimVersion
impl Clone for ScimVersion
Source§fn clone(&self) -> ScimVersion
fn clone(&self) -> ScimVersion
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more