Configory
Configory is a batteries included configuration management library which handles all the gory details of supporting configuration files while also supporting IPC access and overrides.
Example
To get a configuration which is backed by a file that is automatically
reloaded on change, you just need to create a config with Config::new
:
use Config;
let config = new.unwrap;
config.set;
assert_eq!;
This will also automatically spawn an IPC server which allows configuration
file access and modification through a socket file. If you want to disable
this, you can use Config::with_options
.
You can subscribe to the Config::update_rx
channel to receive
notifications about configuration changes and errors:
use ;
let config = new.unwrap;
while let Ok = config.update_rx.recv
IPC client
The client side of the IPC interface is constructed from the socket path,
which can be acquired using Config::ipc
and Ipc::socket_path
.
use Config;
use Ipc;
// This would typically happen in a separate process.
let config = new.unwrap;
let socket_path = config.ipc.unwrap.socket_path;
// Set and retrieve a configuration value through the socket.
let ipc = client;
ipc.set.unwrap;
let value = ipc..unwrap;
assert_eq!;
Struct Deserialization
If you prefer accessing configuration values through a struct rather than
using the dynamic syntax of Config::get
, you can deserialize the
toplevel value into your struct:
use Config;
use Deserialize;
let config = new.unwrap;
// Without configuration file, the default will be empty.
let my_config = config.;
assert_eq!;
// Once changed wit the path syntax, the field will be uptaded.
config.set;
let my_config = config..unwrap;
assert_eq!;