zirv-config
zirv-config is an expandable configuration library for Rust backend applications. It provides a global, mutable configuration store that aggregates settings from multiple subsystems (e.g. server, logging, etc.). Developers can register configuration blocks under namespaces, and later retrieve or update the configuration using convenient macros.
Features
-
Global Configuration Store:
The configuration is maintained as a JSON object in a global store. This store is expandable—subsystems can register their configuration data under a unique namespace. -
Environment Integration:
Automatically loads environment variables (and optionally a.envfile viadotenvy) to initialize configuration values. -
Dynamic Registration:
Easily register new configuration blocks using theregister_config!macro. -
Flexible Access:
Retrieve the entire configuration or a specific configuration value by using dot-separated keys with theread_config!macro. -
Runtime Updates:
Update configuration values at runtime using thewrite_config!macro.
(Note: At present, the write functionality can be added by modifying the global store.)
Installation
Add zirv-config as a dependency in your project's Cargo.toml:
Usage
Before using the macros, initialize the global configuration store. In your application’s startup code, call:
// Initialize the global configuration
init_config;
Registering Configuration Blocks
Register a configuration block under a namespace (for example, "server") using the provided register_config! macro. Any type that implements Serialize can be used.
use register_config;
use Serialize;
Reading Configuration Values
Retrieve the full configuration or a specific key using the read_config! macro. You can also request to deserialize a particular value into a desired type.
use read_config;
License
This project is licensed under the MIT license.
Contributing
Contributions are welcome! Please refer to the contributing guidelines for more information.