Struct apputils::config::Cfg

source ·
pub struct Cfg;
Expand description

Config file helper

A simple helper for managing config files.

Implementations§

source§

impl Cfg

source

pub fn path(appname: &str, file: &str) -> PathBuf

Config file path

Returns the formatted path to a config file of an app.

source

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
Hide additional examples
examples/alacritty.rs (line 7)
5
6
7
8
9
10
11
12
13
14
fn main() {
	paintln!(Colors::Rgb(42, 164, 69), "Attempting to read alacritty config file...");
	match Cfg::read("alacritty", "alacritty.toml") {
		Ok(data) => println!("Your alacritty config:\n{}", data),
		Err(_) => paintln!(Colors::Red, "You don't seem to have an alacritty config!"),
	}

	paintln!(Colors::Rgb(129, 69, 231), "But does your terminal support TrueColor?");
	paintln!(Colors::RgbBold(129, 69, 231), "And does it support Bold Colors???");
}
source

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!

source

pub fn global_path(appname: &str, file: &str) -> PathBuf

Global config file path

Returns the formatted path to an app’s global config file.

source

pub fn global_read(appname: &str, file: &str) -> Result<String>

Read global config

Reads the global config file of an app into a String. Will most likely be parsed, e.g. via Serde.

source

pub fn global_save( appname: &str, file: &str, data: impl AsRef<[u8]> ) -> Result<()>

Save global

Saves to an app’s global config file. Note that this will override the 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> 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>,

§

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

§

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.