Skip to main content

ConfigManager

Struct ConfigManager 

Source
pub struct ConfigManager<T> { /* private fields */ }

Implementations§

Source§

impl<T> ConfigManager<T>

Source

pub fn new() -> Self

Creates a config manager using the OS standard config directory and current executable name.

On Windows desktop apps this resolves under %APPDATA%. Pure UWP apps should use with_root_dir or the optional uwp feature instead.

Source

pub fn at_current_dir(self) -> Self

Stores the settings file in the current working directory.

Source

pub fn with_root_dir<P: Into<PathBuf>>(self, path: P) -> Self

Stores the settings file in a caller-provided directory.

This is the primary compatibility seam for sandboxed hosts, including Pure UWP. The host application may resolve its application data directory and pass it here.

Source

pub fn at_custom_dir<P: Into<PathBuf>>(self, path: P) -> Self

Stores the settings file in a caller-provided directory.

This method is kept for compatibility with v2.0.x. Prefer with_root_dir in new code.

Source

pub fn with_filename(self, name: &str) -> Self

Changes the settings file name.

Source

pub fn disable_pretty_json(self) -> Self

Stores JSON in compact form instead of pretty-printed form.

Source

pub fn folder_path(&self) -> &Path

Returns the settings folder path.

Source

pub fn path(&self) -> PathBuf

Returns the settings file path.

Source

pub fn save(&self, config: &T) -> Result<()>

Saves the complete configuration, replacing the existing file content.

Source

pub fn load(&self) -> Result<T>

Loads a configuration file that is expected to already exist.

Source§

impl<T> ConfigManager<T>

Source

pub fn load_or_default(&self) -> Result<T>

Loads the configuration, or creates and saves T::default() on first run.

Source

pub fn update<F>(&self, f: F) -> Result<T>
where F: FnOnce(&mut T),

Applies a read-modify-write update and saves the result.

Trait Implementations§

Source§

impl<T> Default for ConfigManager<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for ConfigManager<T>

§

impl<T> RefUnwindSafe for ConfigManager<T>
where T: RefUnwindSafe,

§

impl<T> Send for ConfigManager<T>
where T: Send,

§

impl<T> Sync for ConfigManager<T>
where T: Sync,

§

impl<T> Unpin for ConfigManager<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for ConfigManager<T>

§

impl<T> UnwindSafe for ConfigManager<T>
where T: UnwindSafe,

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.