pub trait StorageProvider: Send + Sync {
type Error: Error + Send + Sync + 'static;
// Required methods
fn put(
&self,
key: StorageKey,
data: Value,
) -> impl Future<Output = Result<Value, Self::Error>> + Send;
fn get(
&self,
key: StorageKey,
) -> impl Future<Output = Result<Option<Value>, Self::Error>> + Send;
fn delete(
&self,
key: StorageKey,
) -> impl Future<Output = Result<bool, Self::Error>> + Send;
fn list(
&self,
prefix: StoragePrefix,
offset: usize,
limit: usize,
) -> impl Future<Output = Result<Vec<(StorageKey, Value)>, Self::Error>> + Send;
fn find_by_attribute(
&self,
prefix: StoragePrefix,
attribute: &str,
value: &str,
) -> impl Future<Output = Result<Vec<(StorageKey, Value)>, Self::Error>> + Send;
fn exists(
&self,
key: StorageKey,
) -> impl Future<Output = Result<bool, Self::Error>> + Send;
fn count(
&self,
prefix: StoragePrefix,
) -> impl Future<Output = Result<usize, Self::Error>> + Send;
}Expand description
Core trait for storage providers that handle pure data persistence operations.
This trait defines a protocol-agnostic interface for storing and retrieving JSON data with tenant isolation. Implementations should focus solely on data persistence and retrieval without any SCIM-specific logic.
§Design Principles
- PUT/GET/DELETE Model: Simple, fundamental operations
- PUT Returns Data: Supports SCIM requirement to return resource state after operations
- DELETE Returns Boolean: Indicates whether resource existed (for proper HTTP status codes)
- Tenant Isolation: All operations are scoped to a specific tenant via StorageKey
- Protocol Agnostic: No awareness of SCIM structures or semantics
- Async First: All operations return futures for scalability
- Error Transparency: Storage errors are clearly separated from protocol errors
§Key Design Decisions
- No separate CREATE/UPDATE: Both are just PUT operations. Business logic determines whether this should be treated as create vs update.
- PUT returns stored data: This enables SCIM providers to return the complete resource state after modifications without a separate GET call.
- DELETE returns boolean: Allows proper HTTP status code handling (204 vs 404).
Required Associated Types§
Required Methods§
Sourcefn put(
&self,
key: StorageKey,
data: Value,
) -> impl Future<Output = Result<Value, Self::Error>> + Send
fn put( &self, key: StorageKey, data: Value, ) -> impl Future<Output = Result<Value, Self::Error>> + Send
Store data at the specified key and return the stored data.
§Arguments
key- The storage key identifying the resource locationdata- The JSON data to store
§Returns
The data that was actually stored (may include storage-level metadata).
§Behavior
- If a resource with the same key already exists, it is completely replaced
- The storage implementation should ensure atomic operations where possible
- No validation is performed on the data structure
- The returned data should be exactly what would be retrieved by
get()
Sourcefn get(
&self,
key: StorageKey,
) -> impl Future<Output = Result<Option<Value>, Self::Error>> + Send
fn get( &self, key: StorageKey, ) -> impl Future<Output = Result<Option<Value>, Self::Error>> + Send
Sourcefn delete(
&self,
key: StorageKey,
) -> impl Future<Output = Result<bool, Self::Error>> + Send
fn delete( &self, key: StorageKey, ) -> impl Future<Output = Result<bool, Self::Error>> + Send
Delete data by key.
§Arguments
key- The storage key identifying the resource
§Returns
true if the resource was deleted, false if it didn’t exist.
§Note
This follows SCIM/HTTP semantics where DELETE operations don’t return resource data. The boolean return value allows proper HTTP status code selection (204 vs 404).
Sourcefn list(
&self,
prefix: StoragePrefix,
offset: usize,
limit: usize,
) -> impl Future<Output = Result<Vec<(StorageKey, Value)>, Self::Error>> + Send
fn list( &self, prefix: StoragePrefix, offset: usize, limit: usize, ) -> impl Future<Output = Result<Vec<(StorageKey, Value)>, Self::Error>> + Send
List resources matching a prefix with pagination.
§Arguments
prefix- The storage prefix (tenant + resource type)offset- The number of resources to skip (0-based)limit- The maximum number of resources to return
§Returns
A vector of (key, data) pairs.
§Behavior
- Results should be consistently ordered (e.g., by resource ID)
- If
offsetexceeds the total count, an empty vector should be returned - If
limitis 0, an empty vector should be returned
Sourcefn find_by_attribute(
&self,
prefix: StoragePrefix,
attribute: &str,
value: &str,
) -> impl Future<Output = Result<Vec<(StorageKey, Value)>, Self::Error>> + Send
fn find_by_attribute( &self, prefix: StoragePrefix, attribute: &str, value: &str, ) -> impl Future<Output = Result<Vec<(StorageKey, Value)>, Self::Error>> + Send
Find resources by a specific attribute value.
§Arguments
prefix- The storage prefix (tenant + resource type)attribute- The JSON path of the attribute to search (e.g., “userName”, “emails.0.value”)value- The exact value to match
§Returns
A vector of (key, data) pairs for matching resources.
§Behavior
- Performs exact string matching on the specified attribute
- Supports nested attributes using dot notation
- Returns all matching resources (no pagination)
- Empty vector if no matches found
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.