pub trait TokenStorage: Send + Sync {
// Required methods
fn store(&self, token: &str) -> Result<(), StorageError>;
fn load(&self) -> Result<Option<String>, StorageError>;
fn clear(&self) -> Result<(), StorageError>;
}Expand description
Trait for persistent token storage.
Implement this trait to create custom storage backends for authentication
tokens. The storage must be thread-safe (Send + Sync).
§Platform Examples
- Desktop: Use
FileTokenStorageto store tokens in the user’s config directory - iOS: Implement using Keychain Services
- Android: Implement using EncryptedSharedPreferences
§Example Implementation
ⓘ
use edgefirst_client::{TokenStorage, StorageError};
struct KeychainStorage {
service: String,
account: String,
}
impl TokenStorage for KeychainStorage {
fn store(&self, token: &str) -> Result<(), StorageError> {
// Store in Keychain
Ok(())
}
fn load(&self) -> Result<Option<String>, StorageError> {
// Load from Keychain
Ok(Some("token".to_string()))
}
fn clear(&self) -> Result<(), StorageError> {
// Remove from Keychain
Ok(())
}
}Required Methods§
Sourcefn load(&self) -> Result<Option<String>, StorageError>
fn load(&self) -> Result<Option<String>, StorageError>
Load the stored authentication token.
Returns Ok(None) if no token is stored.
Sourcefn clear(&self) -> Result<(), StorageError>
fn clear(&self) -> Result<(), StorageError>
Clear the stored authentication token.