konfig-rust
A simple, configuration management library for Rust. konfig-rust
lets you focus on app logic and design instead of config management.
This library is a Rust implementation of my konfig-go library.
Features
- Allows for unrelated configuration to live in the same config file
- Automatically manages configuration loading and saving
- Supports JSON, YAML, and TOML formats
- Uses derive macros for easy section definition
- Supports callbacks for custom logic on load and save
- Allows for complete custom flow, since you can decide when the data is saved or loaded
Planned features
- Support more file formats (e.g., environment variables, command-line arguments)
- Allow the user to supply their own format handler
- Have a feature suggestion? Open an issue!
Installation
If you want to use the #[derive(KonfigSection)]
macro, you also need the konfig-rust-derive
crate
Quick Start
This is a very simple example, more complex ones are planned as examples in the github repo.
use ;
use *;
use *;
use KonfigSection;
// Aside from KonfigSection, you also have to use the Serialize and Deserialize macros
Detailed Usage
Configuration Manager Options
The KonfigOptions struct provides several options to customize the behavior of the configuration manager:
/// Options for the KonfigManager
Creating Configuration Sections
Define your configuration struct and derive KonfigSection, Serialize, and Deserialize:
use ;
use KonfigSection;
// Optional: Define section name, defaults to struct name in snake_case
if you want to provide custom validate
and on_load
callbacks, you just have to implement
the KonfigSection
trait manually instead of using the KonfigSection
derive macro
File Formats
konfig-rust supports three configuration file formats, mirroring the Go version:
- JSON (
Format::JSON
): - YAML (
Format::YAML
):my_section: setting1: value setting2: 42 timeout_ms: 30000
- TOML (
Format::TOML
):[] = "value" = 42 = 30000
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License
Author
Created by @kociumba