pub trait StorageBackend: Send + Sync {
Show 16 methods
// Required methods
fn platform_id(&self) -> &str;
fn get(
&self,
namespace: &StorageNamespace,
key: &str,
) -> StorageResult<Option<StorageValue>>;
fn set(
&self,
namespace: &StorageNamespace,
key: &str,
value: StorageValue,
) -> StorageResult<()>;
fn delete(
&self,
namespace: &StorageNamespace,
key: &str,
) -> StorageResult<()>;
fn keys(&self, namespace: &StorageNamespace) -> StorageResult<Vec<String>>;
fn clear(&self, namespace: &StorageNamespace) -> StorageResult<()>;
fn write_file(&self, path: &str, data: &[u8]) -> StorageResult<()>;
fn read_file(&self, path: &str) -> StorageResult<Vec<u8>>;
fn delete_file(&self, path: &str) -> StorageResult<()>;
fn file_exists(&self, path: &str) -> StorageResult<bool>;
fn list_files(&self, dir: &str) -> StorageResult<Vec<String>>;
// Provided methods
fn contains(
&self,
namespace: &StorageNamespace,
key: &str,
) -> StorageResult<bool> { ... }
fn supports_secure(&self) -> bool { ... }
fn secure_set(&self, _key: &str, _value: &[u8]) -> StorageResult<()> { ... }
fn secure_get(&self, _key: &str) -> StorageResult<Option<Vec<u8>>> { ... }
fn secure_delete(&self, _key: &str) -> StorageResult<()> { ... }
}Expand description
Trait that platform-specific storage implementations must implement.
Covers three storage tiers:
- Key-value store (general app data)
- Secure storage (credentials, tokens)
- File storage (documents, media)
Required Methods§
Sourcefn platform_id(&self) -> &str
fn platform_id(&self) -> &str
Platform identifier for this backend.
Sourcefn get(
&self,
namespace: &StorageNamespace,
key: &str,
) -> StorageResult<Option<StorageValue>>
fn get( &self, namespace: &StorageNamespace, key: &str, ) -> StorageResult<Option<StorageValue>>
Get a value by key within a namespace.
Sourcefn set(
&self,
namespace: &StorageNamespace,
key: &str,
value: StorageValue,
) -> StorageResult<()>
fn set( &self, namespace: &StorageNamespace, key: &str, value: StorageValue, ) -> StorageResult<()>
Set a value by key within a namespace.
Sourcefn delete(&self, namespace: &StorageNamespace, key: &str) -> StorageResult<()>
fn delete(&self, namespace: &StorageNamespace, key: &str) -> StorageResult<()>
Delete a key within a namespace.
Sourcefn keys(&self, namespace: &StorageNamespace) -> StorageResult<Vec<String>>
fn keys(&self, namespace: &StorageNamespace) -> StorageResult<Vec<String>>
List all keys in a namespace.
Sourcefn clear(&self, namespace: &StorageNamespace) -> StorageResult<()>
fn clear(&self, namespace: &StorageNamespace) -> StorageResult<()>
Clear all keys in a namespace.
Sourcefn write_file(&self, path: &str, data: &[u8]) -> StorageResult<()>
fn write_file(&self, path: &str, data: &[u8]) -> StorageResult<()>
Write bytes to a file path (relative to app sandbox).
Sourcefn read_file(&self, path: &str) -> StorageResult<Vec<u8>>
fn read_file(&self, path: &str) -> StorageResult<Vec<u8>>
Read bytes from a file path (relative to app sandbox).
Sourcefn delete_file(&self, path: &str) -> StorageResult<()>
fn delete_file(&self, path: &str) -> StorageResult<()>
Delete a file.
Sourcefn file_exists(&self, path: &str) -> StorageResult<bool>
fn file_exists(&self, path: &str) -> StorageResult<bool>
Check if a file exists.
Sourcefn list_files(&self, dir: &str) -> StorageResult<Vec<String>>
fn list_files(&self, dir: &str) -> StorageResult<Vec<String>>
List files in a directory (relative to app sandbox).
Provided Methods§
Sourcefn contains(
&self,
namespace: &StorageNamespace,
key: &str,
) -> StorageResult<bool>
fn contains( &self, namespace: &StorageNamespace, key: &str, ) -> StorageResult<bool>
Check if a key exists within a namespace.
Sourcefn supports_secure(&self) -> bool
fn supports_secure(&self) -> bool
Whether this platform supports secure storage (Keychain, Keystore, etc.).
Sourcefn secure_set(&self, _key: &str, _value: &[u8]) -> StorageResult<()>
fn secure_set(&self, _key: &str, _value: &[u8]) -> StorageResult<()>
Store a value securely (e.g., iOS Keychain, Android Keystore).
Sourcefn secure_get(&self, _key: &str) -> StorageResult<Option<Vec<u8>>>
fn secure_get(&self, _key: &str) -> StorageResult<Option<Vec<u8>>>
Retrieve a securely stored value.
Sourcefn secure_delete(&self, _key: &str) -> StorageResult<()>
fn secure_delete(&self, _key: &str) -> StorageResult<()>
Delete a securely stored value.