pub struct ConfigLoader { /* private fields */ }Expand description
Configuration loader that handles loading and saving configuration files
Implementations§
Source§impl ConfigLoader
impl ConfigLoader
Sourcepub fn new<P: AsRef<Path>>(config_dir: P) -> ConfigResult<Self>
pub fn new<P: AsRef<Path>>(config_dir: P) -> ConfigResult<Self>
Create a new ConfigLoader with the specified directory and default filename
§Errors
This function will return an error if:
- The configuration directory cannot be created
- The configuration file cannot be read or created
- The configuration file contains invalid TOML
Sourcepub fn with_filename<P: AsRef<Path>>(
config_dir: P,
filename: &str,
) -> ConfigResult<Self>
pub fn with_filename<P: AsRef<Path>>( config_dir: P, filename: &str, ) -> ConfigResult<Self>
Create a new ConfigLoader with a specified directory and filename
§Errors
This function will return an error if:
- The configuration directory cannot be created
- The configuration file cannot be read or created
- The configuration file contains invalid TOML
Sourcepub fn get_config(&self) -> &AppConfig
pub fn get_config(&self) -> &AppConfig
Get the current configuration
Sourcepub fn get_config_mut(&mut self) -> &mut AppConfig
pub fn get_config_mut(&mut self) -> &mut AppConfig
Get a mutable reference to the current configuration
Sourcepub fn update_config(&mut self, config: AppConfig) -> ConfigResult<()>
pub fn update_config(&mut self, config: AppConfig) -> ConfigResult<()>
Update the configuration and save changes to disk
§Errors
This function will return an error if:
- The configuration cannot be serialized to TOML
- The configuration file cannot be written to disk
Sourcepub fn reload(&mut self) -> ConfigResult<()>
pub fn reload(&mut self) -> ConfigResult<()>
Reload configuration from disk
§Errors
This function will return an error if:
- The configuration file doesn’t exist
- The configuration file cannot be read
- The configuration file contains invalid TOML
Sourcepub fn save(&self) -> ConfigResult<()>
pub fn save(&self) -> ConfigResult<()>
Save the current configuration to disk
§Errors
This function will return an error if:
- The configuration cannot be serialized to TOML
- The configuration file cannot be written to disk
Sourcepub fn reset_to_defaults(&mut self) -> ConfigResult<()>
pub fn reset_to_defaults(&mut self) -> ConfigResult<()>
Reset the configuration to default values and save to disk
§Errors
This function will return an error if:
- The default configuration cannot be serialized to TOML
- The configuration file cannot be written to disk
Sourcepub fn get_config_path(&self) -> PathBuf
pub fn get_config_path(&self) -> PathBuf
Get the path to the configuration file
Sourcepub fn config_exists(&self) -> bool
pub fn config_exists(&self) -> bool
Check if the configuration file exists
Sourcepub fn validate(&self) -> ConfigResult<()>
pub fn validate(&self) -> ConfigResult<()>
Validate the current configuration
§Errors
This function will return an error if:
- The log level is invalid
- The request timeout is zero
- The parallel validations count is zero
- The minimum success rate is outside the range 0.0 to 1.0
- The auto-save interval is zero
Sourcepub fn create_snapshot(&self) -> ConfigResult<PathBuf>
pub fn create_snapshot(&self) -> ConfigResult<PathBuf>
Create a snapshot of the configuration with the current timestamp
§Errors
This function will return an error if:
- The backups directory cannot be created
- The configuration cannot be serialized to TOML
- The snapshot file cannot be written
Sourcepub fn list_snapshots(&self) -> ConfigResult<Vec<PathBuf>>
pub fn list_snapshots(&self) -> ConfigResult<Vec<PathBuf>>
List all configuration snapshots
§Errors
This function will return an error if:
- The backups directory cannot be read
- There’s an error reading directory entries
- There’s an error getting file metadata
Sourcepub fn restore_from_snapshot(
&mut self,
snapshot_path: &Path,
) -> ConfigResult<()>
pub fn restore_from_snapshot( &mut self, snapshot_path: &Path, ) -> ConfigResult<()>
Restore configuration from a snapshot
§Errors
This function will return an error if:
- The snapshot file doesn’t exist
- The snapshot file cannot be read
- The snapshot file contains invalid TOML
- The restored configuration cannot be saved