Expand description
Type-safe persisted values API for storing application configuration and state. Type-safe persisted values API for storing application configuration and state.
This module provides a type-safe key-value API for storing persisted values. Each persisted value resolves to its own backend, defaulting to the SDK-managed database.
§Usage
ⓘ
use bitwarden_state::register_persisted_value;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
struct AppConfig {
theme: String,
auto_save: bool,
}
// Register a type-safe key
register_persisted_value!(CONFIG: AppConfig = "app_config");
// Access persisted values via client.platform().state().value()
async fn example(client: &bitwarden_core::Client) -> Result<(), Box<dyn std::error::Error>> {
// Get a persisted value handle
let value = client.platform().state().value::<CONFIG>();
// Get value
let config: Option<AppConfig> = value.try_get().await?;
// Update value
let new_config = AppConfig {
theme: "dark".to_string(),
auto_save: true,
};
value.set(new_config).await?;
// Delete value
value.remove().await?;
Ok(())
}Modules§
- handle 🔒
- Persisted value types for type-safe access to individual persisted values.
- key 🔒
- Type-safe keys for persisted values storage.
Structs§
- Persisted
Value - A handle to a single persisted value in storage.
Enums§
- Persisted
Value Error - Errors that can occur when working with persisted values.
Traits§
- Persisted
Value Key - Type-safe key for persisted values storage.