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>
impl<TConfigData: Serialize + DeserializeOwned + Default> Config<TConfigData>
Sourcepub fn load(config_file_key: &str) -> Result<Self, ConfigError>
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.
Sourcepub fn save(&self) -> Result<(), ConfigError>
pub fn save(&self) -> Result<(), ConfigError>
Flush config changes to disk.
pub fn data(&self) -> &TConfigData
pub fn data_mut(&mut self) -> &mut TConfigData
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more