Simple platform-agnostic Rust crate for managing application settings/preferences.
Install the crate as a dependency in your app's Cargo.toml file:
toml
[dependencies]
abserde = "0.3.2"
Import Abserde, associated definitions, and serde::Serialize, and serde::Deserialize:
rust
use abserde::*;
use serde::{Serialize, Deserialize};
Define a struct to store your app config. You must derive your struct from serde::Serialize and serde::Deserialize traits.
```rust use std::collections::HashMap;
struct MyConfig {
windowwidth: usize,
windowheight: usize,
windowx: usize,
windowy: usize,
theme: String,
user_data: HashMap
Create an Abserde instance to manage how your configuration is stored on disk:
rust
let my_abserde = Abserde {
app: "MyApp".to_string(),
location: Location::Auto,
format: Format::Json,
};
Load data into config from disk:
rust
let my_config = MyConfig::load_config(&my_abserde)?;
Save config data to disk:
rust
my_config.save_config(&my_abserde)?;
Delete config file from disk:
rust
my_abserde.delete()?;