pub struct Config {
pub file: PathBuf,
pub path: PathBuf,
}Fields§
§file: PathBufFilename of the current configuration file (default config.toml)
path: PathBufDirectory that contains the configuration files
Implementations§
Source§impl Config
impl Config
pub fn new(dir: ConfigDirectory) -> Result<Self, ConfigError>
Sourcepub fn set_file(&mut self, file: impl Into<PathBuf>) -> &mut Self
pub fn set_file(&mut self, file: impl Into<PathBuf>) -> &mut Self
Changes the current configuration file
Sourcepub fn with_file(self, file: impl Into<PathBuf>) -> Self
pub fn with_file(self, file: impl Into<PathBuf>) -> Self
Builder pattern to set the current configuration file
Sourcepub fn read<T: DeserializeOwned>(&self) -> Result<T, ConfigError>
pub fn read<T: DeserializeOwned>(&self) -> Result<T, ConfigError>
Reads and deserializes the configuration file into type T
Sourcepub fn read_or_default<T: Serialize + DeserializeOwned + Default>(
&self,
) -> Result<T, ConfigError>
pub fn read_or_default<T: Serialize + DeserializeOwned + Default>( &self, ) -> Result<T, ConfigError>
Reads and deserializes the configuration file into type T. If missing config is written
and returns T::default()
Sourcepub fn write<T: Serialize>(&self, data: &T) -> Result<(), ConfigError>
pub fn write<T: Serialize>(&self, data: &T) -> Result<(), ConfigError>
Serializes and writes data T to disk as pretty TOML file.
Loads the config and stores it in a thread safe SharedConfig
Loads the config, writes and returns T::default() if missing, and stores it in a thread safe SharedConfig
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
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