6 releases

0.1.6 Feb 11, 2024
0.1.5 Feb 11, 2024
0.1.2 Jul 24, 2022
0.1.1 Apr 26, 2022

#387 in Configuration

Download history 4/week @ 2024-11-13 4/week @ 2024-11-20 2/week @ 2024-11-27 20/week @ 2024-12-04 26/week @ 2024-12-11 24/week @ 2024-12-18 3/week @ 2024-12-25 20/week @ 2025-01-01 32/week @ 2025-01-08 39/week @ 2025-01-15 22/week @ 2025-01-22 14/week @ 2025-01-29 14/week @ 2025-02-05 27/week @ 2025-02-12 46/week @ 2025-02-19 53/week @ 2025-02-26

144 downloads per month
Used in 2 crates

GPL-2.0 license

22KB
248 lines

libset

A configuration file management library for Rust applications.

Add the library

Run cargo add libset or add it to Cargo.toml:

[dependencies]
libset = "0.1"

Usage

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.

Write a file.

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

Get a file.

#[derive(Debug, Serialize, Deserialize)]
struct Colors { accent: String }
let settings: Colors = config.get_json("colors")?;

Check out the examples!

Scopes

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

Available features

  • 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.

Proposals

If you have a proposal for a new feature, open a new issue.

Dependencies

~3–17MB
~182K SLoC