Module settings

Module settings 

Source
Expand description

Type-safe settings repository for storing application configuration and state. Type-safe settings repository for storing application configuration and state.

This module provides a type-safe key-value API for storing settings, backed by the SDK’s repository pattern.

§Usage

use bitwarden_state::register_setting_key;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
struct AppConfig {
    theme: String,
    auto_save: bool,
}

// Register a type-safe key
register_setting_key!(const CONFIG: AppConfig = "app_config");

// Access settings via client.platform().state().setting()
async fn example(client: &bitwarden_core::Client) -> Result<(), Box<dyn std::error::Error>> {
    // Get a setting handle
    let setting = client.platform().state().setting(CONFIG)?;

    // Get value
    let config: Option<AppConfig> = setting.get().await?;

    // Update value
    let new_config = AppConfig {
        theme: "dark".to_string(),
        auto_save: true,
    };
    setting.update(new_config).await?;

    // Delete setting
    setting.delete().await?;

    Ok(())
}

Modules§

key 🔒
Type-safe keys for settings storage.
setting 🔒
Setting types for type-safe access to individual settings.

Structs§

Key
Type-safe key for settings storage.
Setting
A handle to a single setting value in storage.

Enums§

SettingsError
Errors that can occur when working with settings.