Expand description

Simple platform-agnostic Rust crate for managing application settings/preferences.

Installation

Install the crate as a dependency in your app’s Cargo.toml file:

[dependencies]
abserde = "0.4.1"

Usage

Import Abserde, associated definitions, and serde::Serialize, and serde::Deserialize:

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.

use std::collections::HashMap;

#[derive(Serialize, Deserialize)]
struct MyConfig {
	window_width: usize,
	window_height: usize,
	window_x: usize,
	window_y: usize,
	theme: String,
	user_data: HashMap<String, String>,
}

Create an Abserde instance to manage how your configuration is stored on disk:

let my_abserde = Abserde::default();

Using Abserde in this way will use your crate as the name for the app config directory.

Alternatively, you can also pass options to Abserde to change the location or format of your config file:

let my_abserde = Abserde {
	app: "MyApp".to_string(),
	location: Location::Auto,
	format: Format::Json,
};

Load data into config from disk:

let my_config = MyConfig::load_config(&my_abserde)?;

Save config data to disk:

my_config.save_config(&my_abserde)?;

Delete config file from disk:

my_abserde.delete()?;

Structs

Represents an Abserde app, specifying how app settings are to be managed.

Enums

Storage format for app config.

Represents the location of a config file.

Traits

Trait that apps can implement to store app settings.

Type Definitions

Alias for generic Error type.

Alias for Result type wrapping generic Error type.