bitwarden_state/persisted_value/mod.rs
1//! Type-safe persisted values API for storing application configuration and state.
2//!
3//! This module provides a type-safe key-value API for storing persisted values. Each persisted
4//! value resolves to its own backend, defaulting to the SDK-managed database.
5//!
6//! # Usage
7//!
8//! ```rust,ignore
9//! use bitwarden_state::register_persisted_value;
10//! use serde::{Deserialize, Serialize};
11//!
12//! #[derive(Serialize, Deserialize)]
13//! struct AppConfig {
14//! theme: String,
15//! auto_save: bool,
16//! }
17//!
18//! // Register a type-safe key
19//! register_persisted_value!(CONFIG: AppConfig = "app_config");
20//!
21//! // Access persisted values via client.platform().state().value()
22//! async fn example(client: &bitwarden_core::Client) -> Result<(), Box<dyn std::error::Error>> {
23//! // Get a persisted value handle
24//! let value = client.platform().state().value::<CONFIG>();
25//!
26//! // Get value
27//! let config: Option<AppConfig> = value.try_get().await?;
28//!
29//! // Update value
30//! let new_config = AppConfig {
31//! theme: "dark".to_string(),
32//! auto_save: true,
33//! };
34//! value.set(new_config).await?;
35//!
36//! // Delete value
37//! value.remove().await?;
38//!
39//! Ok(())
40//! }
41//! ```
42
43mod handle;
44mod key;
45
46pub use handle::{PersistedValue, PersistedValueError, PersistedValueItem, PersistedValueTrait};
47pub use key::PersistedValueKey;
48
49/// This code is not meant to be used directly, users of this crate should use the
50/// [crate::register_persisted_value] macro to declare their keys.
51#[doc(hidden)]
52pub mod ___internal {
53
54 // This trait is in an internal module to forbid users from implementing `PersistedValueKey`
55 // directly.
56 pub trait Internal {}
57}
58pub(crate) use ___internal::Internal;