Skip to main content

ConfigLoader

Struct ConfigLoader 

Source
pub struct ConfigLoader { /* private fields */ }
Expand description

Configuration loader that handles loading and saving configuration files

Implementations§

Source§

impl ConfigLoader

Source

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
Source

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
Source

pub fn get_config(&self) -> &AppConfig

Get the current configuration

Source

pub fn get_config_mut(&mut self) -> &mut AppConfig

Get a mutable reference to the current configuration

Source

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
Source

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
Source

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
Source

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
Source

pub fn get_config_path(&self) -> PathBuf

Get the path to the configuration file

Source

pub fn config_exists(&self) -> bool

Check if the configuration file exists

Source

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
Source

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
Source

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
Source

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more