#home #config-file

home-config

Use configuration file in the HOME directory

1 unstable release

0.6.0 Nov 1, 2022
0.5.0 Sep 14, 2022
0.4.0 May 24, 2022
0.3.0 May 23, 2022
0.1.0 Mar 5, 2022

#645 in Configuration

Download history 168/week @ 2024-07-28 57/week @ 2024-08-04 90/week @ 2024-08-11 120/week @ 2024-08-18 192/week @ 2024-08-25 133/week @ 2024-09-01 113/week @ 2024-09-08 134/week @ 2024-09-15 176/week @ 2024-09-22 132/week @ 2024-09-29 49/week @ 2024-10-06 69/week @ 2024-10-13 113/week @ 2024-10-20 149/week @ 2024-10-27 130/week @ 2024-11-03 49/week @ 2024-11-10

446 downloads per month
Used in 3 crates

MIT license

14KB
230 lines

home-config

Crates.io docs.rs LICENSE

Use configuration file in the HOME directory

Usage

use home_config::HomeConfig;

let config = HomeConfig::with_config_dir("app", "config");
// Linux: /home/name/.config/app/config
// macOS: /Users/name/.config/app/config
// Windows: C:\Users\name\.config\app\config

// Write
config.save("123456789").unwrap();

// Read
let data = config.read_to_string().unwrap();
// 123456789

Serde format support

home-config = { version = "*", features = ["json", "yaml", "toml", "hcl"] }

A JSON example:

use home_config::HomeConfig;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Default)]
struct People {
    name: String,
    age: u32,
}

let config = HomeConfig::with_file("test.json");
// Linux: /home/name/test.json
// macOS: /Users/name/test.json
// Windows: C:\Users\name\test.json

// Parse
let people = config.json::<People>().unwrap();
// people.name == "XiaoMing";
// people.age == 18;

// Save to file
config.save_json(&people).unwrap();

Dependencies

~0–1.4MB
~26K SLoC