pub struct Cfg;Expand description
Config file helper
A simple helper for managing config files.
Implementations§
source§impl Cfg
impl Cfg
sourcepub fn path(appname: &str, file: &str) -> PathBuf
pub fn path(appname: &str, file: &str) -> PathBuf
Config file path
Returns the formatted path to a config file of an app.
sourcepub fn read(appname: &str, file: &str) -> Result<String>
pub fn read(appname: &str, file: &str) -> Result<String>
Read config file
Reads an app’s config file into a String. This can then be used to parse it via Serde.
Examples found in repository?
examples/wallpaper-dl.rs (line 10)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
fn main() {
paint!(Colors::Green, "Your wallpaper-dl config: ");
match Cfg::read(APP_NAME, CONFIG_FILE) {
Err(_) => paintln!(Colors::YellowBold, "Not found"),
Ok(x) => println!("\n{x}")
}
println!("\n{}\n", "=".repeat(36));
paint!(Colors::Blue, "Your wallpaper database: ");
match Appdata::read_str(APP_NAME, DB_FILE) {
Err(_) => paintln!(Colors::RedBold, "Not found"),
Ok(x) => println!("\n{x}")
}
}More examples
sourcepub fn save(appname: &str, file: &str, data: impl AsRef<[u8]>) -> Result<()>
pub fn save(appname: &str, file: &str, data: impl AsRef<[u8]>) -> Result<()>
Save config file
Saves to an app’s config file. Note that this will override the file!
sourcepub fn global_path(appname: &str, file: &str) -> PathBuf
pub fn global_path(appname: &str, file: &str) -> PathBuf
Global config file path
Returns the formatted path to an app’s global config file.
Auto Trait Implementations§
impl Freeze for Cfg
impl RefUnwindSafe for Cfg
impl Send for Cfg
impl Sync for Cfg
impl Unpin for Cfg
impl UnwindSafe for Cfg
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