Crates.io | libset |
lib.rs | libset |
version | 0.1.6 |
source | src |
created_at | 2022-04-26 18:47:01.487291 |
updated_at | 2024-02-11 08:03:14.262859 |
description | A configuration file management library for Rust applications. |
homepage | https://libset.edfloreshz.dev/ |
repository | https://github.com/edfloreshz/libset/ |
max_upload_size | |
id | 575648 |
size | 52,458 |
A configuration file management library for Rust applications.
Run cargo add libset
or add it to Cargo.toml
:
[dependencies]
libset = "0.1"
Start by creating a new Config
object:
let config = Config::new("org.example.Demo", 1, None)?;
Provide an application name, a version and optionally a prefix, then, a new directory will be added to your filesystem, this is where all the created files will be stored in.
let config = Config::new("org.example.Demo", 1, None)?;
config.set_json("colors", json!({ "accent": "#7a7af9" }))?;
This wil store the file here:
$HOME/.config/org.example.Demo/v1/colors.json
#[derive(Debug, Serialize, Deserialize)]
struct Colors { accent: String }
let settings: Colors = config.get_json("colors")?;
Check out the examples!
A scope is just a simple sub-directory stored inside your application's config directory, all subsequent files will be stored within that scope.
let config = Config::new("org.example.Demo", 1, Some("appearance"))?;
config.set_json("colors", json!({ "accent": "#7a7af9" }))?;
This wil store the file here:
$HOME/.config/org.example.Demo/v1/appearance/colors.json
json
- Enables json support, enabled by default.toml
- Enables toml support.ron
- Enables ron support.Depending on which features you enable, you will get setter and getters methods suffixed by the file type.
If you have a proposal for a new feature, open a new issue.