claude_code_toolkit/traits/
config.rs

1//! Configuration provider traits
2
3use crate::error::Result;
4use crate::types::Config;
5use async_trait::async_trait;
6use std::any::Any;
7use std::path::Path;
8
9/// Trait for configuration providers (YAML, JSON, environment, etc.)
10#[async_trait]
11pub trait ConfigProvider: Send + Sync {
12  /// Load configuration from the provider
13  async fn load_config(&self) -> Result<Config>;
14
15  /// Save configuration to the provider
16  async fn save_config(&self, config: &Config) -> Result<()>;
17
18  /// Validate configuration format and structure
19  async fn validate_config(&self, config: &Config) -> Result<()>;
20
21  /// Check if configuration exists
22  async fn config_exists(&self) -> Result<bool>;
23
24  /// Get configuration file path (if applicable)
25  fn config_path(&self) -> Option<&Path>;
26
27  /// Downcasting support for concrete implementations
28  fn as_any(&self) -> &dyn Any;
29}
30
31/// High-level configuration management interface
32#[async_trait]
33pub trait ConfigManager: Send + Sync {
34  /// Initialize configuration with defaults
35  async fn initialize(&self) -> Result<Config>;
36
37  /// Load current configuration
38  async fn load(&self) -> Result<Config>;
39
40  /// Save configuration
41  async fn save(&self, config: &Config) -> Result<()>;
42
43  /// Update specific configuration section
44  async fn update_section<T>(&self, section: &str, data: T) -> Result<()> where T: Send + Sync;
45
46  /// Backup current configuration
47  async fn backup(&self) -> Result<String>;
48
49  /// Restore from backup
50  async fn restore(&self, backup_id: &str) -> Result<()>;
51}