pub trait ConfigService: Send + Sync {
// Required methods
fn get_config(&self) -> Result<Config>;
fn reload(&self) -> Result<()>;
fn save_config(&self) -> Result<()>;
fn save_config_to_file(&self, path: &Path) -> Result<()>;
fn get_config_file_path(&self) -> Result<PathBuf>;
fn get_config_value(&self, key: &str) -> Result<String>;
fn reset_to_defaults(&self) -> Result<()>;
fn set_config_value(&self, key: &str, value: &str) -> Result<()>;
}Expand description
Configuration service trait for dependency injection.
This trait abstracts configuration loading and reloading operations, allowing different implementations for production and testing environments.
Required Methods§
Sourcefn get_config(&self) -> Result<Config>
fn get_config(&self) -> Result<Config>
Get the current configuration.
Returns a clone of the current configuration state. This method may use internal caching for performance.
§Errors
Returns an error if configuration loading or validation fails. Get the current configuration.
Returns the current Config instance loaded from files,
environment variables, and defaults.
§Errors
Returns an error if configuration loading fails due to:
- Invalid TOML format in configuration files
- Missing required configuration values
- File system access issues
Sourcefn reload(&self) -> Result<()>
fn reload(&self) -> Result<()>
Reload configuration from sources.
Forces a reload of configuration from all sources, discarding any cached values.
§Errors
Returns an error if configuration reloading fails.
Sourcefn save_config(&self) -> Result<()>
fn save_config(&self) -> Result<()>
Save current configuration to the default file location.
§Errors
Returns an error if:
- Unable to determine config file path
- File system write permissions are insufficient
- TOML serialization fails
Sourcefn save_config_to_file(&self, path: &Path) -> Result<()>
fn save_config_to_file(&self, path: &Path) -> Result<()>
Sourcefn get_config_file_path(&self) -> Result<PathBuf>
fn get_config_file_path(&self) -> Result<PathBuf>
Get the default configuration file path.
§Returns
Returns the path where configuration files are expected to be located,
typically $CONFIG_DIR/subx/config.toml.
Sourcefn get_config_value(&self, key: &str) -> Result<String>
fn get_config_value(&self, key: &str) -> Result<String>
Sourcefn reset_to_defaults(&self) -> Result<()>
fn reset_to_defaults(&self) -> Result<()>
Reset configuration to default values.
This will overwrite the current configuration file with default values and reload the configuration.
§Errors
Returns an error if save or reload fails.
Sourcefn set_config_value(&self, key: &str, value: &str) -> Result<()>
fn set_config_value(&self, key: &str, value: &str) -> Result<()>
Set a specific configuration value by key path.
§Arguments
key: Dot-separated path to the configuration valuevalue: New value as string (will be converted to appropriate type)
§Errors
Returns an error if validation or persistence fails, including:
- Unknown configuration key
- Type conversion or validation error
- Failure to persist configuration