Struct Config

Source
pub struct Config<TConfigData: Serialize + DeserializeOwned + Default> { /* private fields */ }
Expand description

Generic struct for managing an app’s chunk of config data on disk.

Saves config files in $ILO_CONFIG_HOME, or ~/.config/ilo/ if the former is not set.

About the DeserializeOwned trait bound: see https://serde.rs/lifetimes.html. Since the struct itself is loading the data from a file, it’s in command of its own deserializer lifetimes.

Implementations§

Source§

impl<TConfigData: Serialize + DeserializeOwned + Default> Config<TConfigData>

Source

pub fn load(config_file_key: &str) -> Result<Self, ConfigError>

Load a config based on a key.

The file and directory creation is lazy, i.e. if the JSON file does not exist, a default config will be loaded and the file will not actually be created until there is a write.

Source

pub fn save(&self) -> Result<(), ConfigError>

Flush config changes to disk.

Source

pub fn data(&self) -> &TConfigData

Source

pub fn data_mut(&mut self) -> &mut TConfigData

Trait Implementations§

Source§

impl<TConfigData: Serialize + DeserializeOwned + Default + Debug> Debug for Config<TConfigData>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<TConfigData> Freeze for Config<TConfigData>
where TConfigData: Freeze,

§

impl<TConfigData> RefUnwindSafe for Config<TConfigData>
where TConfigData: RefUnwindSafe,

§

impl<TConfigData> Send for Config<TConfigData>
where TConfigData: Send,

§

impl<TConfigData> Sync for Config<TConfigData>
where TConfigData: Sync,

§

impl<TConfigData> Unpin for Config<TConfigData>
where TConfigData: Unpin,

§

impl<TConfigData> UnwindSafe for Config<TConfigData>
where TConfigData: 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.