| Crates.io | ezcfg |
| lib.rs | ezcfg |
| version | 0.1.2 |
| created_at | 2025-11-19 10:09:37.71696+00 |
| updated_at | 2026-01-07 02:21:19.151209+00 |
| description | A simple library for simple configuration. |
| homepage | |
| repository | https://github.com/j-stach/ezcfg |
| max_upload_size | |
| id | 1939824 |
| size | 11,173 |
A simple library for simple configuration.
ezcfg to your Rust project:cargo add ezcfg
crate_cfg or pub_cfg macro to define a struct with your configurable values. FromStr and Display.use ezcfg::{ crate_cfg, Config };
crate_cfg!{
MyConfig ["~/.path/to.cfg"]
version: semver::Version,
description: String,
some_value: u8
}
crate_cfg macro is public within your crate, while the struct created by pub_cfg is exportable.let my_config = MyConfig {
version: semver::Version::new(0, 0, 1),
description: String::from("This is my configuration"),
some_value: 69u8,
};
my_config.write().unwrap();
The file at ~/.path/to.cfg will look like this:
version=0.0.1
description=This is my configuration
some_value=69
let mut my_config = MyConfig::read().unwrap();
assert_eq!(my_config.some_value, 69u8);
my_config.version = semver::Version::new(0, 0, 2);
my_config.some_value = 42u8;
my_config.write().unwrap();
The file will be changed:
version=0.0.2
description=This is my configuration
some_value=42
let path = MyConfig::PATH;
assert_eq!(path, "~/.path/to.cfg");
Please note that the macros expect a single ident token for each type when defining fields.
To use generic types and full module paths as field types, first set up an alias that describes the desired type in a single identifier token:
// Will fail to compile:
crate_cfg!{
BadConfig ["~/.badcfg"]
field: Type<T>,
}
// Do this:
type TypeT = Type<T>;
crate_cfg!{
OkConfig ["~/.okcfg"]
field: TypeT,
}
Also note that each line obeys field=value, where value can be any type that is representable in string form, as long as the formatted string does not contain the characters \n or =.
0.1.1, there are different macros for public and private configuration structs.0.0.2, the empty line bug is fixed.This crate is mostly complete, and designed to be lightweight and minimal.
New features (e.g., provided methods for Config) may be added later if their absence is salient.
If you encounter any bugs, please leave an issue!