Expand description
In-memory storage implementation for SCIM resources.
This module provides a thread-safe in-memory implementation of the StorageProvider
trait using HashMap and RwLock for concurrent access. It’s designed for testing,
development, and scenarios where persistence is not required.
§Features
- Thread-safe concurrent access with async RwLock
- Automatic tenant isolation through hierarchical key structure
- Efficient querying with attribute-based searches
- Consistent ordering for list operations
- No external dependencies beyond standard library
§Performance Characteristics
- PUT/GET/DELETE: O(1) average case
- LIST with pagination: O(n) where n is total resources in prefix
- FIND_BY_ATTRIBUTE: O(n) with JSON parsing overhead
- EXISTS/COUNT: O(1) and O(n) respectively
§Example Usage
use scim_server::storage::{InMemoryStorage, StorageProvider, StorageKey};
use serde_json::json;
let storage = InMemoryStorage::new();
// Store a user
let key = StorageKey::new("tenant1", "User", "user123");
let user_data = json!({
"id": "user123",
"userName": "john.doe",
"displayName": "John Doe",
"emails": [{"value": "john@example.com", "primary": true}]
});
let stored = storage.put(key.clone(), user_data).await?;
println!("Stored: {}", stored);
// Retrieve the user
let retrieved = storage.get(key.clone()).await?;
assert!(retrieved.is_some());
// Search by email
let prefix = StorageKey::prefix("tenant1", "User");
let found = storage.find_by_attribute(prefix, "emails.0.value", "john@example.com").await?;
assert_eq!(found.len(), 1);
// Delete the user
let was_deleted = storage.delete(key).await?;
assert!(was_deleted);Structs§
- InMemory
Storage - Thread-safe in-memory storage implementation.
- InMemory
Storage Stats - Statistics about the current state of in-memory storage.