| Crates.io | home-config |
| lib.rs | home-config |
| version | 0.7.0 |
| created_at | 2022-03-05 17:01:14.638578+00 |
| updated_at | 2026-01-25 03:40:18.710778+00 |
| description | Use configuration file in the HOME directory |
| homepage | https://github.com/wyhaya/home-config |
| repository | https://github.com/wyhaya/home-config.git |
| max_upload_size | |
| id | 544125 |
| size | 25,229 |
Use configuration file in the HOME directory
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
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();