Crates.io | appconfig |
lib.rs | appconfig |
version | 0.2.1 |
source | src |
created_at | 2021-03-06 09:19:17.021843 |
updated_at | 2024-04-18 23:36:23.712163 |
description | A simple configuration file manager for desktop applications |
homepage | https://github.com/sumibi-yakitori/appconfig |
repository | https://github.com/sumibi-yakitori/appconfig |
max_upload_size | |
id | 364719 |
size | 11,620 |
A simple configuration file manager for desktop applications.
The configuration file is read from and written to the following locations.
Platform | Value | Example |
---|---|---|
Linux | $XDG_DATA_HOME or $HOME /.local/share |
/home/alice/.local/share |
macOS | $HOME /Library/Application Support |
/Users/Alice/Library/Application Support |
Windows | {FOLDERID_LocalAppData} |
C:\Users\Alice\AppData\Local |
cargo add appconfig serde
use std::{cell::RefCell, rc::Rc};
use appconfig::AppConfigManager;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct MyAppConfig {
window_pos: (u32, u32),
}
impl Default for MyAppConfig {
fn default() -> Self {
Self {
window_pos: (320, 280),
}
}
}
fn main() {
let config = Rc::from(RefCell::from(MyAppConfig::default()));
let manager = AppConfigManager::new(
config.clone(),
std::env!("CARGO_CRATE_NAME"), // CRATE_BIN_NAME etc..,
"sumibi-yakitori",
);
manager.save().unwrap();
manager.load().unwrap();
assert_eq!(*config.borrow(), MyAppConfig::default());
}