Skip to main content

ConfigService

Trait ConfigService 

Source
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<()>;
    fn load_for_repair(&self) -> Result<Config>;
}
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§

Source

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
Source

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.

Source

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
Source

fn save_config_to_file(&self, path: &Path) -> Result<()>

Save configuration to a specific file path.

§Arguments
  • path: Target file path for the configuration
§Errors

Returns an error if:

  • TOML serialization fails
  • Unable to create parent directories
  • File write operation fails
Source

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.

Source

fn get_config_value(&self, key: &str) -> Result<String>

Get a specific configuration value by key path.

§Arguments
  • key: Dot-separated path to the configuration value (e.g., “ai.provider”)
§Errors

Returns an error if the key is not recognized.

Source

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.

Source

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 value
  • value: 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
Source

fn load_for_repair(&self) -> Result<Config>

Load the configuration from the file only without applying environment-variable overlays and without invoking the cross-section validator.

This is the “tolerant load” path used exclusively by the config subcommand handlers (set, get, list) so that users can inspect and repair an on-disk configuration that fails strict cross-section validation. The pre-existing strict load (ConfigService::get_config) is unchanged and continues to drive every other code path.

The returned Config reflects the file’s view of the configuration. Successful invocations of this method MUST NOT populate the strict-config cache: only configurations that have passed cross-section validation may enter the cache.

§Errors

Returns an error if:

  • The file cannot be read.
  • The file is not valid TOML.
  • The file’s contents cannot be deserialized into a Config (i.e. an individual field has the wrong type).

Implementors§